Thread: pointer trouble

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    84

    pointer trouble

    hello, I have a file I want to read and overwrite... right now I'm just going to try and overwrite it with the same information until i get this part straight... the code I have is giving me an error saying I have conflicting types for fptr.... the file I'm trying to access is a text file with a few lines of text....

    could anyone tell me why I'm getting this error. Thank you

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    #define Max_Size 80
     
    
    
    
    /***** Pointers for input and output files******/
                     
                     FILE *fptr;
                     fptr = fopen("morse.txt","r+");
                     
    /******************************/
                     
                 
                 
                 
                 
    main() {
           
    /* This is used to store the output lines */    
    
       char line[Max_Size + 1]  
    
    
          
           while ( fgets ( line, Max_Size + 1, fptr ) != NULL)
           
           fputs( line, fptr);
           
           fclose(fptr);
           return EXIT_SUCCESS; }

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Declare it locally in main(), not globally.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define Max_Size 80
     
    main() {         
    /***** Pointers for input and output files ******/
       FILE *fptr;
       fptr = fopen("morse.txt","r+");
    /**************************************/
    
    /* This is used to store the output lines */ 
       char line[Max_Size + 1];  
      
           while ( fgets ( line, Max_Size + 1, fptr ) != NULL)       
                fputs( line, fptr);
           
           fclose(fptr);
           return EXIT_SUCCESS; 
    }
    Last edited by SlyMaelstrom; 10-29-2005 at 01:01 AM.
    Sent from my iPadŽ

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Actually, you can declare it globally. You just can't have your call to fopen out there. That being said, I wouldn't suggest using a global here. But you're allowed to, that is, the language doesn't prevent it.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Replies: 4
    Last Post: 06-15-2005, 08:30 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM