View Single Post
Old Feb 19, 2009, 01:29 AM   #9
binsky3333
500 Posts
 
binsky3333's Avatar
 
Join Date: Jul 2007
Posts: 624 (0.29/day)
Thanks: 12
Thanked 22 Times in 17 Posts

System Specs

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);
__________________
Check out my FPS Engine
http://forums.techpowerup.com/showthread.php?t=88124


Last edited by binsky3333; Feb 19, 2009 at 01:46 AM.
binsky3333 is offline  
Reply With Quote