i'm suppose to use this code to rotate characters from this input file (blah_input.txt)....
Now is the time for all good persons to come to the aid of their
party. Hello world! 1234 !@#$
to this output file(blah_output.txt)...
Abj vf gur gvzr sbe nyy tbbq crefbaf gb pbzr gb gur nvq bs gurve
cnegl. Uryyb jbeyq! 1234 !@#$
instead i just end up with chinese characters for some reason....help please.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int (encode(int input_char));
int main(void)
{
FILE * in;
FILE * out;
char input_char;
int char_total = 0;
in = fopen("blah_input.txt", "r");
if(in == NULL)
{
printf("Sorry, unable to open input file.\n");
exit(1);
}
out = fopen("blah_output.txt", "w");
if (out == NULL)
{
printf("Sorry, unable to open output file.\n");
exit(1);
}
while ((input_char = fgetc(in)) != EOF)
{
fputc(encode(input_char), out);
char_total = char_total + 1;
}
fprintf(out, "\n%d characters", char_total);
fclose(in);
fclose(out);
return 0;
}
int encode(int input_char)
{
if (('a' <= input_char) && (input_char <= 'm'))
{
return input_char + 13;
}
else if (('n' <= input_char) && (input_char <= 'z'))
{
return input_char - 13;
}
if (('A' <= input_char) && (input_char <= 'M'))
{
return input_char + 13;
}
else if (('N' <= input_char) && (input_char <= 'Z'))
{
return input_char - 13;
}
}