Converts command-line argument to number - C Function

C examples for Function:main function

Description

Converts command-line argument to number

Demo Code

#include <stdio.h> 
#include <stdlib.h> 
            /*ww  w  .  j  av a2s .  co m*/
int main(int argc, char *argv[]){ 
      int i, times; 
   
      if (argc < 2 || (times = atoi(argv[1])) < 1) 
          printf("Usage: %s positive-number\n", argv[0]); 
      else 
          for (i = 0; i < times; i++) 
              puts("Hello, good looking!"); 
   
      return 0; 
}

Related Tutorials