Problem with outputting to a file

This is a discussion on Problem with outputting to a file within the C Programming forums, part of the General Programming Boards category; Hello everybody, I've been having trouble outputting text to a FILE. This is the code I've been trying to use ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Problem with outputting to a file

    Hello everybody, I've been having trouble outputting text to a FILE. This is the code I've been trying to use

    Code:
    FILE *outLog;
    outLog = fopen("PortLog", "w");
    fclose(outLog);
    fputs("Hello",outLog);
    fclose(outLog);
    ...with stdio.h included. It will let me actually open the file, but nothing will print out to it. Can someone please help me? (I'm sorry I can't provide the entirety of the code as it is much too long to be practically printed here

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    You are closing the file before you write to it... Get rid of that first fclose function call.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    34
    Touche, good sir. I must admit I feel like quite the idiot right now.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    actually - this is pure C not C++ (and should be on C forum)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,931
    It is C++, though it happens to be written in the subset of C++ that is standard C.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    Yes, but there's little point to having questions that are entirely in C on the C++ board even if they are technically C++ also.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,931
    Yes, but there's little point to having questions that are entirely in C on the C++ board even if they are technically C++ also.
    That's true... but it is rather irritating. I wish people would be more explicit if they actually want to ask a C++ question with code that is pretty much just C.

    But anyway, I'll just move this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Problem with file and array
    By paok in forum C Programming
    Replies: 5
    Last Post: 05-01-2008, 04:19 AM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM

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