Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:12:51+00:00 2026-06-15T00:12:51+00:00

This C program I am making reads a set of chars from the command

  • 0

This C program I am making reads a set of chars from the command line and stores them using an array (argv[]) like so

main (int argc, char *argv[])  {
int temp;
     /*prevents no arguments*/
if (argc==1){
    printf("Usage;\t[0 < integers < 9] [operators]\n");
    exit(0);
}
int i;
for (i = 0 ; i<argc; i++){
    temp = argv[i] - '0';
    printf("this is char %d ; %d\n",i, temp);
}
}

But all I get after running it in the command line like so;

    program 2 4 1 - +

is random garbage

    this is char 0 ; -4195956
    this is char 1 ; -4195950
    this is char 2 ; -4195948
    this is char 3 ; -4195946
    this is char 4 ; -4195944
    this is char 5 ; -4195942

Is there something wrong with the way I’m casting temp? Or am I just getting the idea of pointers (in *argv[]) wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:12:52+00:00Added an answer on June 15, 2026 at 12:12 am
    char *argv[]
    

    argv is an array of pointers to char. So argv[X] is a pointer to char (for suitable X). So argv[X] - some_integral_value is pointer arithmetic, and returns a pointer (if that subtraction is defined).

    To access the first element, you need argv[X][0].

    Please note that argv[0] is not the first argument but (usually) the program name. Arguments start at argv[1].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a program that reads and stores data from Windows EventLog files
I'm making a program in Java that reads in some stuff from a file
I am making a program that opens and reads a file. This is my
I am going to be making a program that reads in a line and
I am making a program with native C++ and the WinAPI. This program has
I'm making this little program because I was bored and I ran across this
I am making this assignment in my program and I am getting the warning
I was making this very simple lex program (just an introductory program). But on
This program I use has it's own variables to set when you run it,
This program stores pairs in a map, counting the number of times a word

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.