fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. static char * const ARGV[] = { "a.out", "444" };
  5.  
  6. // Hack for IDE One not taking command line params
  7. int realMain(int argc, char *argv[])
  8. {
  9. if (argc < 2)
  10. return EXIT_FAILURE; // TODO print out the correct usage of the command line to the user
  11.  
  12. char *endPointer = NULL;
  13. long in;
  14.  
  15. in = strtol(argv[1], &endPointer, 10);
  16.  
  17. if (endPointer != NULL) {
  18. switch( in )
  19. {
  20. case 1: printf("1\n");
  21. break;
  22. case 2: printf("2\n");
  23. break;
  24. default: printf("wrong value\n");
  25. break;
  26. }
  27. return EXIT_SUCCESS;
  28. }
  29. return EXIT_FAILURE;
  30. }
  31.  
  32. int main(int argc, char *argv[]) {
  33. realMain(2, ARGV);
  34. }
  35.  
Success #stdin #stdout 0s 2292KB
stdin
a.out 1
stdout
wrong value