input value from terminal to c 1

input value from terminal to c

#include 
#include 

int main(int argc, char *argv[])
{
   int rings;
   if(argc != 2) {
       printf("Usage: %s number-of-rings\n",argv[0]);
       return 1;
   }

   rings = atoi(argv[1]);
   printf("Using number-of-rings = %d\n", rings);
...

   return 0;
}

Here is what the above code is Doing:
1. The first line of the program is a comment.
2. The next line includes the stdio.h header file. This file contains the definitions of the standard input/output library functions.
3. The next line includes the stdlib.h header file. This file contains the definitions of the standard library functions.
4. The next line defines the main function. This is the function that is called when the program is run.
5. The next line declares the variable rings.
6. The next line checks to see if the program was run with the correct number of arguments. If not, it prints a usage message and returns 1.
7. The next line converts the string argument to an integer and assigns it to the rings variable.
8. The next line prints the value of the rings variable.
9. The next line is a comment.
10. The next line returns 0.

Similar Posts