Thread: Outputting Files

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    61

    Outputting Files

    Hi There,

    I have a c code that produces a list of numbers,

    What is the easiest way I can output these to a file that I can see in excel (so i can make a graph).

    Currently the code is in a loop that produces 12,000 results based on the previous result.

    It currently uses the printf function to prodcue the answers on a screen.

    James

  2. #2
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Make it a tab or comma separated file, you can import that to excel.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well if you have
    1,2,3

    Then you can just do something like
    myprog.exe > myresults.csv

    Double-clicking on that file in explorer should run excel automatically and import the data.

    If you've got any other kind of separator, then just run excel and do "import file", where you have the chance to specify all sorts of things like field widths, formats, separators etc.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    61
    really daft so i have my printf (Input)

    Loop

    printf(Output)

    How do i print these to a file?
    Ive only ever outputed data as printf()

    James

  5. #5
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    You need to open a new file for writing using fopen, then you write to it using fprintf (almost identical syntax to printf) and close it again with fclose. Or you can do what Salem says and redirect the output directly to a file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. outputting to file?
    By TonyG in forum C Programming
    Replies: 4
    Last Post: 05-17-2011, 04:55 AM
  2. Not outputting the right response...
    By Taka in forum C Programming
    Replies: 1
    Last Post: 09-13-2006, 07:36 AM
  3. Outputting a menu
    By Guti14 in forum C++ Programming
    Replies: 6
    Last Post: 08-28-2003, 06:33 PM
  4. outputting picture
    By wayko in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2001, 05:53 AM