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

    1
    file.txt
    2
    1
    text.txt
    0
    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!