GNU Compiling Question

This is a discussion on GNU Compiling Question within the C++ Programming forums, part of the General Programming Boards category; I have this program that compiles and runs in microsoft C++ but when I try to compile with GNU either ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    28

    GNU Compiling Question

    I have this program that compiles and runs in microsoft C++ but when I try to compile with GNU either no output is produced or the output file is put somewhere and I don't know where it is! I am using the gcc command to compile. Should that put the output file in the same directory as my .c file? Or is my problem of a different nature?

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    First off, thank you very much for the help!
    There is an fprintf in the .c file. So it should be printing to that file right? Also, if I open the a.out file there's a bunch of unreadable stuff in the file.
    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");
    
             for(j=1; j<max && fscanf(input, "%c", &data[j]) != EOF; j++)
             {
    
                                    if (data[j] == ' ')
                    {
                        i++;
                                    }
    
                                    if(i < 4  || i >= 7)
     {
                      fputc (data[j], output);
                     }
    
                                    if (data[j] == '\n')
                                    {
                                             j=0;
                                             i=0;
                                    }
    
         }
    
             fclose (input);
             fclose(output); 
    
         return 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    Also, previously this:
    Code:
     fprintf (output, "%c", data[j]);
    was in the place of:
    Code:
     fputc (data[j], output);
    but that did not work either.

  4. #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-08-2003 at 12:52 AM.

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, 05:22 AM
  2. Question with compiling
    By glory in death in forum C++ Programming
    Replies: 2
    Last Post: 04-06-2007, 07:02 PM
  3. Exam Question - Possible Mistake?
    By Richie T in forum C++ Programming
    Replies: 15
    Last Post: 05-08-2006, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21