Advertisement
SpiralLaser

Untitled

Jan 31st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. int arg;
  7. for(arg = 0; arg < argc; arg++)
  8. {
  9. if(argv[arg][0] == ‘-‘)
  10. printf(“option: %s\n”, argv[arg]+1);
  11. else
  12. printf(“argument %d: %s\n”, arg, argv[arg]);
  13. }
  14. exit(0);
  15. }
  16.  
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <stdlib.h>
  20. int main(int argc, char *argv[])
  21. {int opt;
  22. while((opt = getopt(argc, argv, “:if:lr”)) != -1) {
  23. switch(opt) {
  24. case ‘i’:
  25. case ‘l’:
  26. case ‘r’:
  27. printf(“option: %c\n”, opt);
  28. break;
  29. case ‘f’:
  30. printf(“filename: %s\n”, optarg);
  31. break;case ‘:’:
  32. printf(“option needs a value\n”);
  33. break;case ‘?’:
  34. printf(“unknown option: %c\n”, optopt);
  35. break;
  36. }
  37. }
  38. for(; optind < argc; optind++)
  39. printf(“argument: %s\n”, argv[optind]);
  40. exit(0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement