Ut oh guys... It looks like i have another problem...
Here is my code:
Code:
int viewer()
{
FILE *file;
char c;
char fileparam[80];
char write[256];
printf("Type the filename (this will create a new file or edit an existing one) = ");
scanf("%s", fileparam);
file = fopen(fileparam, "a+w");
if(file==NULL) {
printf("Error: can't open file.\n");
/* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */
return 1;
}
else {
printf("File opened successfully\nContents:\n\n");
while(1) { /* keep looping... */
c = fgetc(file);
if(c!=EOF) {
printf("%c", c);
/* print the file one character at a time */
}
else {
break; /* ...break when EOF is reached */
}
}
printf("\n\n");
getchar();
printf("Please enter the text you would like to add to the file:");
fgets( write, 256, stdin );
fprintf(file, "%s", write);
printf("successful!\n");
system("pause");
apps();
}
}
Now the problem i am having is with the apps(); . Whenever i have this in the code, the text that is supposed to be written to the file is not... But whenever i take out apps(); the text is written to the file, but then the program stops because its the end of it... the apps(); is redirecting it to another function in another header file. How can i fix this problem?
EDIT: Nevermind i fixed the problem i just had to add fclose(file);