writing contents of array to file

This is a discussion on writing contents of array to file within the C Programming forums, part of the General Programming Boards category; fprintf(string, "%f", array[0]); That statement above writes to a data file but stops after about a hundreds line are written. ...

  1. #1
    Unregistered
    Guest

    Cool writing contents of array to file

    fprintf(string, "%f", array[0]);

    That statement above writes to a data file but stops after about a hundreds line are written. The data that is stored in array[0] is created as the file is being written (dynamically??)

    How do I code so that I can continously write to a file as the data is being created?

    Thanks,

    Donald

  2. #2
    Unregistered
    Guest

    Thumbs up

    sprintf(string, " %g", draw_geom_buf.value[0]);
    fprintf(output,"%s\n",string);

    this the actual code sorry.

    Donald

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > How do I code so that I can continously write to a file as the data is being created
    Can you explain how this is being achieved?

    In a single thread, you're either modifying the array or writing to the file.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: writing contents of array to file

    Originally posted by Unregistered
    How do I code so that I can continously write to a file as the data is being created?
    Where is the input coming from? You need to control the input loop somehow. Bit difficult to advise without seeing more code really.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Unregistered
    Guest

    Talking

    I have it. I forgot to fclose(output); this flushes all the data created during the execution of the main program to the output file after the main program is exited.

    The data is basically written to the file during the execution of the program then when you exit the program the rest of the data stored in the array is flushed out to the data file.

    Without fclose() the rest of the data that is stored in the array is not written to the data file, resulting in a inacurate data file.

    Once again fclose() saves the day.

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 Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  3. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

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