fork(1) download
  1. #include <stdio.h>
  2. #define INPUT_FILE 1 //define statements
  3. #define OUTPUT_FILE 2
  4. #define NUM_TO_SHIFT 3
  5. #define ENCODE 4
  6. #define QUIT 0
  7.  
  8. int menu(); //function prototypes
  9. int input();
  10. int output();
  11. int shift();
  12. int encode();
  13. void quit();
  14.  
  15. int main()
  16. {
  17. int choice; // main variables
  18. char user_filename[100];
  19.  
  20. choice = menu(); // get user's first selection
  21.  
  22. while(choice != QUIT) //execute so long as choice is not equal to QUIT
  23. {
  24. switch(choice)
  25. {
  26. case INPUT_FILE:
  27. printf("Enter the filename of the file to encode:\n");
  28. printf("(hit the Enter key when done)\n");
  29. //gets(user_filename);
  30. scanf("%s", user_filename);
  31. printf("Getting %s\n", user_filename);
  32. break;
  33. case OUTPUT_FILE: output();
  34. break;
  35. case NUM_TO_SHIFT: shift();
  36. break;
  37. case ENCODE: encode();
  38. break;
  39. case QUIT: quit();
  40. break;
  41. default: printf("Oops! An invalid choice slipped through. ");
  42. printf("Please try again.\n");
  43. }
  44. choice = menu(); /* get user's subsequent selections */
  45. }
  46.  
  47. printf("Bye bye!\n");
  48. return 0;
  49. }
  50.  
  51. int menu(void)
  52. {
  53. int option;
  54.  
  55. printf("Text Encoder Service\n\n");
  56. printf("1.\tEnter name of input file (currently 'Secret.txt')\n");
  57. printf("2.\tEnter name of output file (currently not set)\n");
  58. printf("3.\tEnter number of characters data should be shifted (currently +7)\n");
  59. printf("4.\tEncode the text\n\n");
  60. printf("0.\tQuit\n\n");
  61. printf("Make your selection: ");
  62.  
  63. while( (scanf(" %d", &option) != 1) /* non-numeric input */
  64. || (option < 0) /* number too small */
  65. || (option > 4)) /* number too large */
  66. {
  67. fflush(stdin); /* clear bad data from buffer */
  68. printf("That selection isn't valid. Please try again.\n\n");
  69. printf("Your choice? ");
  70. }
  71. printf("Selecting %d\n", option);
  72. return option;
  73. }
  74.  
  75. int input()
  76. {
  77.  
  78. }
  79.  
  80. int output()
  81. {
  82. return 2;
  83. }
  84.  
  85. int shift()
  86. {
  87. return 3;
  88. }
  89.  
  90. int encode()
  91. {
  92. return 4;
  93. }
  94.  
  95. void quit()
  96. {
  97. printf("Quiting...Bye!");
  98. exit(0);
  99. }
Success #stdin #stdout 0.02s 1724KB
stdin
1
file.txt
2
1
text.txt
0
stdout
Text Encoder Service

1.	Enter name of input file (currently 'Secret.txt')
2.	Enter name of output file (currently not set)
3.	Enter number of characters data should be shifted (currently +7)
4.	Encode the text

0.	Quit

Make your selection: Selecting 1
Enter the filename of the file to encode:
(hit the Enter key when done)
Getting file.txt
Text Encoder Service

1.	Enter name of input file (currently 'Secret.txt')
2.	Enter name of output file (currently not set)
3.	Enter number of characters data should be shifted (currently +7)
4.	Encode the text

0.	Quit

Make your selection: Selecting 2
Text Encoder Service

1.	Enter name of input file (currently 'Secret.txt')
2.	Enter name of output file (currently not set)
3.	Enter number of characters data should be shifted (currently +7)
4.	Encode the text

0.	Quit

Make your selection: Selecting 1
Enter the filename of the file to encode:
(hit the Enter key when done)
Getting text.txt
Text Encoder Service

1.	Enter name of input file (currently 'Secret.txt')
2.	Enter name of output file (currently not set)
3.	Enter number of characters data should be shifted (currently +7)
4.	Encode the text

0.	Quit

Make your selection: Selecting 0
Bye bye!