outputting to file?

This is a discussion on outputting to file? within the C Programming forums, part of the General Programming Boards category; What am i missing? This creates a file but does not write to it. Code: void foo (struct* current, char ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    53

    outputting to file?

    What am i missing? This creates a file but does not write to it.

    Code:
    void foo (struct* current, char inputID) {
    
    FILE *stdoutReport;
        char *reportFile;
    
        if (current != NULL) {
            if (strcmp(current->categoryID, inputID) == 0) {
                strncat(inputID, ".report\0", REPORT_SIZE);
                reportFile = inputID;
                stdoutReport = fopen(reportFile, "wa");
                if (!stdoutReport)
                    printf("Error creating file. %s", reportFile);
    
                fprintf(stdoutReport, "Category %s - %s - Detailed Report\n",
                       current->categoryID, current->categoryName);
                fprintf(stdoutReport, "----------------------------");
                fprintf(stdoutReport, "-----------------------------\n");

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,261
    O_o

    That "wa" there isn't a valid mode of operation.

    Soma

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by TonyG View Post
    What am i missing? This creates a file but does not write to it.

    Code:
    void foo (struct* current, char inputID) {
    
    FILE *stdoutReport;
        char *reportFile;
    
        if (current != NULL) {
            if (strcmp(current->categoryID, inputID) == 0) {
                strncat(inputID, ".report\0", REPORT_SIZE);
                reportFile = inputID;
                stdoutReport = fopen(reportFile, "wa");
                if (!stdoutReport)
                    printf("Error creating file. %s", reportFile);
    
                fprintf(stdoutReport, "Category %s - %s - Detailed Report\n",
                       current->categoryID, current->categoryName);
                fprintf(stdoutReport, "----------------------------");
                fprintf(stdoutReport, "-----------------------------\n");
    You need to look at your fopen() options again... I don't believe you can combine w and a.

  4. #4
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    stdoutReport = fopen(reportFile, "w");
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    53
    Yeh thanks all. Was late and i was tired. Didn't even have fclose() in the code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Outputting into a PDF file
    By allen9190 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2010, 10:15 PM
  2. Problem with outputting to a file
    By LowlyIntern in forum C Programming
    Replies: 6
    Last Post: 08-14-2008, 02:55 PM
  3. Dev-C++ outputting .exe file
    By Yuri in forum C++ Programming
    Replies: 3
    Last Post: 12-18-2005, 11:14 AM
  4. outputting to another file
    By mcorn in forum C Programming
    Replies: 12
    Last Post: 08-11-2002, 10:33 PM
  5. outputting to a file
    By simhap in forum C++ Programming
    Replies: 7
    Last Post: 11-20-2001, 01:16 PM

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