Thread: GNU Compiling Question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    I added the code above. I am not familiar with perror but I assume that if that condition was true it would have reported that error during compiling. The program compiled fine and when I added fprintf (output, "Outside") and another one that should print "inside" in the loop just to see if I could write to the file at all. This did not print to the file either. This leads me to believe I have some error in opening the file or in my syntax in writing to the file. Thanks again for the help, it is very appreciated.

    The code again, for reference:
    Code:
    #include <stdio.h>
    #define max 5000
    
    int main (void)
    {
    
         char data [max];
         int j = 0, i=0;
         FILE* input;
         FILE* output;
    
    
         input = fopen ("input_40x10x300_nohead.cor", "r");   //open the input file
         output = fopen ("input_new_40x10x300.cor", "w");
    
            if ( input == NULL ) {
        perror( "Can't open input file" );
        exit( 1 );
    }
    
            fprintf (output, "outside");
             for(j=1; j<max && fscanf(input, "%c", &data[j]) != EOF; j++)
             {
    
    
                                    if (data[j] == ' ')
                    {
                        i++;
                                    }
    
                                    if(i < 4  || i >= 7)
     {
                       fprintf (output, "%c", data[j]);
                       fprintf (output, "inside");
            }
    
                                    if (data[j] == '\n')
                                    {
                                             j=0;
                                             i=0;
                                    }
    
         }
    
             fclose (input);
             fclose(output);
    
         return 0;
    *edit: code was only half there.
    Last edited by PunkyBunny300; 04-07-2003 at 11:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. Question with compiling
    By glory in death in forum C++ Programming
    Replies: 2
    Last Post: 04-06-2007, 06:02 PM
  3. Exam Question - Possible Mistake?
    By Richie T in forum C++ Programming
    Replies: 15
    Last Post: 05-08-2006, 03:44 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Simple Compiling question ...
    By hypertension in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2003, 01:02 PM