Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. ### getargs demo
  2.  
  3. #include <unistd.h>
  4. #include <stdio.h>
  5.  
  6. int main (int argc, char *argv[])
  7. {
  8. int ch;
  9. int avgSec = 0;
  10.  
  11. if (argc == 1) {
  12. printf ("You specified no parameters.\n");
  13. }
  14.  
  15. while ((ch = getopt(argc, argv, "a:fhm:z")) != -1) {
  16. switch (ch) {
  17. case 'a':
  18. printf ("You specified the -a option ");
  19. printf ("with the parameter \"%s\".\n", optarg);
  20. avgSec = atoi(optarg);
  21. printf ("Will run for %d seconds and calculate avg fps.\n", avgSec);
  22. break;
  23. case 'f':
  24. printf ("You specified the -f option.\n");
  25. printf ("Starting in fullscreen mode.\n");
  26. break;
  27. case 'h':
  28. printf ("You specified the -h option.\n");
  29. printf ("Usage info goes here.\n");
  30. break;
  31. case 'm':
  32. printf ("You specified the -m option ");
  33. printf ("with the parameter \"%s\".\n", optarg);
  34. //printf ("Starting in mode %d.\n", atoi(optarg));
  35. break;
  36. case 'z':
  37. printf ("You specified the -z option.\n");
  38. printf ("Starting in zoomed (windowed) mode.\n");
  39. break;
  40. default:
  41. printf ("You specified a parameter I don't know about.\n");
  42. break;
  43. }
  44. }
  45. argc -= optind;
  46. argv += optind;
  47.  
  48. return avgSec;
  49. }
Add Comment
Please, Sign In to add comment