I have written a program that encrypts text files using Caesar cipher, however, there is an error i cannot find which prevents the code from running. Could someone tell me where i'm going wrong:
before any administrator closes this thread for "ask for you to do my homework" i would like to make it clear that i am NOT doing that,i'm simply looking for some guidance.
#include <stdio.h> int main(void) { FILE *file_in; char filename[20]; char ch; int shift; // file_in is the name given to the stream. filename will be the file that the user chooses. ch is the characters in the file. printf("What file do you want to open?: "); gets(filename); file_in=fopen(filename, "r"); //ask the user to enter the name of a file if(file_in==NULL) printf("Error! File did not open.\n"); //print message if the file can not be found while((ch=fgetc(file_in)) != EOF) putchar(ch); //putchar prints the results on the screen and shows the end of the file printf("What file do you want to encrypt?: "); gets(filename); file_in=fopen(filename, "r"); //ask the user to enter the name of a file if(file_in==NULL) printf("Error! File did not open.\n"); //print message if the file can not be found scanf("Enter shift: %d",shift); if (shift<1 || shift >25) printf("invalid shift amount"); char ch = 'A'; ch = ch + shift; printf("%c", ch); fclose(file_in); //closes stream }
before any administrator closes this thread for "ask for you to do my homework" i would like to make it clear that i am NOT doing that,i'm simply looking for some guidance.