The aim of this program is to read a message on a file using fscanf and print it to another file while encrypting it by cycling it k number of places where k is user-defined from 0-9. So far I've written a large amount of code but I think there's something wrong with it because it's not scanning anything.

I'm supposed to encrypt the following:

abcdef uvwxyz ZYXWVUTS RQPONML 102378

by cycling it "k" number of places using the ASCII numbers

Now for some reason it's reading the scanf value but it doesn't write anything. It appears to go into the if/else loops but nothing happens.Code:#include <stdio.h> FILE *f_in, *f_out; int var, k, status; char output, chrr; main() { printf("Enter a value from 0 to 9.\n"); scanf("%d", &k); if (k>=0 && k<=9) { f_in = fopen("message.txt", "r"); f_out = fopen("encrypted.txt", "w"); //status = fscanf (f_in, "%c", &var); //chrr = (int) input while (var != EOF) { fscanf(f_in, "%d", &var); fscanf(f_in, "%c", &chrr); if ((chrr>=48) && (chrr<=57)) { if (chrr==57) { if(k==0) { output=57; fprintf( f_out, "%c", output); printf("%c", output); } else { output=47+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==56) { if(k<=1) { output=56+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=46+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==55) { if(k<=2) { output=55+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=45+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==54) { if(k<=3){ output=54+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=44+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==53) { if(k<=4){ output=53+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=43+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==52) { if(k<=5){ output=52+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=42+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==51) { if(k<=6){ output=51+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=41+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==50) { if(k<=7){ output=50+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=40+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==49) { if(k<=8){ output=49+k; fprintf( f_out, "%c", output); printf("%c", output); } else { output=39+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr==48) { output=48+k; fprintf( f_out, "%c", output); printf("%c", output); } } else if ((chrr>='a') && (chrr<='z')) { if (chrr=='z') { if(k==0){ output=122; fprintf( f_out, "%c", output); printf("%c", output); } else { output=96+k; fprintf( f_out,"%c", output); printf("%c",output); } } if (chrr=='y') { if(k==0 || k==1) { output=121+k; fprintf( f_out, "%c", output); } else { output=95+k; fprintf( f_out, "%c", output); } } if (chrr=='x') { if(k>=0 && k<=2) { output=120+k; fprintf( f_out, "%c", output); } else { output=94+k; fprintf( f_out, "%c", output); } } if (chrr=='w') { if(k<=3) { output=119+k; fprintf( f_out, "%c", output); } else { output=93+k; fprintf( f_out, "%c", output); } } if (chrr=='v') { if(k<=4) { output=118+k; fprintf( f_out, "%c", output); } else { output=92+k; fprintf( f_out, "%c", output); } } if (chrr=='u') { if(k<=5) { output=117+k; fprintf( f_out, "%c", output); } else { output=91+k; fprintf( f_out, "%c", output); } } if (chrr=='t') { if(k<=6) { output=116+k; fprintf( f_out, "%c", output); } else { output=90+k; fprintf( f_out, "%c", output); } } if (chrr=='s') { if(k<=7) { output=115+k; fprintf( f_out, "%c", output); } else { output=89+k; fprintf( f_out, "%c", output); } } if (chrr=='r') { if(k<=8) { output=114+k; fprintf( f_out, "%c", output); } else { output=88+k; fprintf( f_out, "%c", output); } } else { while((chrr>='a') && (chrr<='q')) { output=(chrr+k); fprintf( f_out, "%c", output); printf("%c", output); break; } } } else if (chrr>='A' && chrr<='Z') { if (chrr=='Z') { if(k==0){ output=90; fprintf( f_out, "%c", output); } else { output=64+k; fprintf( f_out,"%c", output); } } if (chrr=='Y') { if(k==0 || k==1) { output=89+k; fprintf( f_out, "%c", output); } else { output=63+k; fprintf( f_out, "%c", output); } } if (chrr=='X') { if(k>=0 && k<=2) { output=88+k; fprintf( f_out, "%c", output); } else { output=62+k; fprintf( f_out, "%c", output); } } if (chrr=='W') { if(k<=3) { output=87+k; fprintf( f_out, "%c", output); } else { output=61+k; fprintf( f_out, "%c", output); } } if (chrr=='V') { if(k<=4) { output=86+k; fprintf( f_out, "%c", output); } else { output=60+k; fprintf( f_out, "%c", output); } } if (chrr=='U') { if(k<=5) { output=85+k; fprintf( f_out, "%c", output); } else { output=59+k; fprintf( f_out, "%c", output); } } if (chrr=='T') { if(k<=6) { output=84+k; fprintf( f_out, "%c", output); } else { output=58+k; fprintf( f_out, "%c", output); } } if (chrr=='S') { if(k<=7) { output=83+k; fprintf( f_out, "%c", output); } else { output=57+k; fprintf( f_out, "%c", output); } } if (chrr=='R') { if(k<=8) { output=82+k; fprintf( f_out, "%c", output); } else { output=56+k; fprintf( f_out, "%c", output); } } else if (chrr>='A' && chrr<='Q') { output=(chrr+k); fprintf( f_out, "%c", output); printf("%c", output); } } else { output=chrr; fprintf( f_out, "%c", output); printf("%c", output); break; } } fclose(f_in); fclose(f_out); } /* else { printf("The integer is not from 0 to 9"); break; } */ }

*EDIT* ok i put in the fscanf()'s inside the loop and changed their condition, now all my program is doing is printing d to the screen.

*EDIT* It looks like it's encryping the first character in the loop then it's not stopping, perhaps it needs breaks?