Advertisement
cd62131

ARGS check

Feb 28th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. int main(int argc, char **argv) {
  5.   char *p;
  6.   int a, b;
  7.   if (argc != 3) exit(1);
  8.   for (p = argv[1]; *p; p++) if (!isdigit(*p)) exit(1);
  9.   for (p = argv[2]; *p; p++) if (!isdigit(*p)) exit(1);
  10.   a = atoi(argv[1]);
  11.   b = atoi(argv[2]);
  12.   if (100 < a || 100 < b) exit(1);
  13.   printf("argv[1]: %d, argv[2]: %d\n", a, b);
  14.   return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement