Advertisement
Guest User

Untitled

a guest
May 1st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5.  
  6. #define TRUE 1
  7. #define FALSE 0
  8.  
  9. char giTextValue[8000];
  10.  
  11. int main (int argc, char **argv)
  12. {
  13. int aflag = FALSE;
  14. int bflag = FALSE;
  15. char *cvalue = NULL;
  16. int index;
  17. int c;
  18.  
  19. opterr = FALSE;
  20.  
  21. memset( &giTextValue, 0x20, sizeof( giTextValue ) );
  22.  
  23. while ((c = getopt (argc, argv, "abc:")) != -1) {
  24. switch (c) {
  25. case 'a':
  26. aflag = TRUE;
  27. break;
  28. case 'b':
  29. bflag = TRUE;
  30. break;
  31. case 'c':
  32. cvalue = optarg;
  33. break;
  34. case '?':
  35. if (optopt == 'c')
  36. fprintf (stderr, "Option -%c requires an argument.\n", optopt);
  37. else if (isprint (optopt))
  38. fprintf (stderr, "Unknown option `-%c'.\n", optopt);
  39. else
  40. fprintf (stderr,
  41. "Unknown option character `\\x%x'.\n",
  42. optopt);
  43. return 1;
  44. default:
  45. abort ();
  46. } // END OF SWITCH
  47. }
  48.  
  49. printf ("aflag = %d, bflag = %d, cvalue = %s\n",aflag, bflag, cvalue);
  50.  
  51. for (index = optind; index < argc; index++)
  52. printf ("Non-option argument %s\n", argv[index]);
  53.  
  54. // DO SOMETHING FROM PARAMETER
  55. if( aflag == TRUE )
  56. giTextValue[5000] = 1;
  57. else
  58. giTextValue[5000] = 0;
  59.  
  60. if( bflag == TRUE )
  61. giTextValue[5000] = 2;
  62. else
  63. giTextValue[5000] = 0;
  64.  
  65. giTextValue[5001] = cvalue;
  66.  
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement