felmkern
2012-11-26 05:02:46 UTC
When I run this code it tells me that the file has been read but it only prints one character and the character is never one from the file itself but just a random character such as # * & á
/* A program which encrypts a text file named by the user */
#include
#include
#include
#define maxname 50 //sets maximum number of file name characters to 50
#define maxtext 10000//sets maximum number of characters read in to 10000
int main(void)
{
char name[maxname];//char name[max 50]
char text[maxtext];//char name[max 10000]
FILE *file_in;
FILE *file_out;
int c;
printf("Please enter the name of the file you wish to encrypt \nincluding the file type e.g. .txt : ");//ask user for the name of the file
scanf("%s", name);//name entered given to array name
if((file_in = fopen(name, "r")) == NULL)//file open assigned to file_in and null check performed. Null check stops the program running for an infinite number of times.
{
printf("\nError. Could not open file.\n");
exit(EXIT_FAILURE);
}
else {
do
{
fscanf(file_in, "%c", text);
for(c=0; c!=EOF; c++);
{
printf("%c", text[c]);
}
}
while(!feof(file_in));
}
fclose(file_in);
return 0;
}