Question: My code appears strange and garbled. There may be a problem with initialization. How can I modify it? #include #include //encrypt method void encrypt(char *message,

My code appears strange and garbled. There may be a problem with initialization. How can I modify it?

#include

#include

//encrypt method

void encrypt(char *message, int date[], int n)

{

int i = 0, j = 0;

//Using while function to ignore the empty spaces

while(message[i] != '\0')

{

char ch = message[i];

//From A to Z

if(ch >= 65 && ch

{

ch = ch + date[j];

//Wraping-around if there is an overflow

if(ch > 90)

ch = ch % 90 + 64;

j++;

}

//From a to z

if(ch >= 97 && ch

{

ch = ch + date[j];

//Wraping-around if there is an overflow

if(ch > 122)

ch = ch % 122 + 96;

j++;

}

j = j % n;

message[i] = ch;

i++;

}

}

int main()

{

char input_file[100], message[10000], input_date[6];

int date[6], i;

//Setting up File variables

FILE *fp, *fpout;

printf("Enter the file name: ");

scanf("%s", input_file);

//Error for file doesn't exist

if ((fp = fopen(input_file, "r")) == NULL)

{

printf("Error! File Not Found ");

return 0;

}

printf("Enter date in the format of 6 digit: ");

scanf("%s", input_date);

for(i = 0; i

date[i] = input_date[i] - 48;

//Creating and open the encrypt file

fpout = fopen(strcat(input_file, ".ecp"), "w+");

if(fpout == NULL)

{

printf("Error! Unable to create file ");

return 0;

}

//Reads each line of the file and store them in message variable

while(fgets(message, sizeof(message), fp) != NULL)

{

//Calling encrypt method

encrypt(message, date, 6);

//Writes encrypted message in the new file

fprintf(fpout, "%s", message);

}

printf("Output file name: %s ", input_file);

//Close files

fclose(fp);

fclose(fpout);

return 0;

}

My code appears strange and garbled. There may be a problem with

[ xwei@scln1 ~]$ nano P6. C [ xwei@scln1 ~]$ gcc -Wall P6. c [ xwei@scln1 ~]$ ./try_date_encrypt Enter the file name: Enter date in the format of 6 digit: Output file name: inpu t message . txt . ecp J igbzm sbfjw bubvjww boppcwdff upnz xkmt jxf i bz hamn ditdcb ujelmct uq upn gittb ixgoby gjxf xnpqnf eqp demt ro. Jv twdoeu njmf ndo. Mgua jmm ebtu bof hw cphgupns. Expected: Enter file name: input_message . txt Enter the date in the format of 6 digit: 112189 igbzm sbfjw bubvjww boppcwdff upnz xkmt hixf ifbz hsmn ditdcb ujelmet uq upn gittb uxgobh gjxf xnpqnf eqp demt ro. Jv twdoeu njmf ndo. Mgua jmm ebtu bof hw cphgupns. Enter the file name: Enter date in the format of 6 digit: Output file name: inpu [ message2 . txt . ecp Nix dnmnx xist mifw jwu Qpqkiy rjjob ax olum. Avslcm ax bujidi xhhzirh d ymd xjh. Slf zptl etn wu jpu ape gpuymcx ultm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!