Two Questions - Return at end of paired data points in CSV file, and how to "break"
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Two Questions - Return at end of paired data points in CSV file, and how to "break"

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    34

    Two Questions - Return at end of paired data points in CSV file, and how to "break"

    I am using the following line to write pairs of data files. I am hoping to create a CSV file.

    CODE fprintf(f, "%d,%f", Universe.year, Universe.R); CODE


    This simply writes pairs of data on the same line. I'd like pairs of data on individual lines. This means I need to insert a line feed, somehow, perhaps via a character insertion. Could someone please tell me how to do this easily?

    Finally, my memory is very vague on C programming. Is the proper means to exit a loop an if then statement containing the term "break"? How would that be implemented?

    Thank you!
    Last edited by Protocol; January 24th, 2013 at 12:54 PM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,429

    Re: Two Questions - Return at end of paired data points in CSV file, and how to "brea

    Code tags are done like this:
    [code]
    Your code goes here
    [/code]

    This simply writes pairs of data on the same line. I'd like pairs of data on individual lines. This means I need to insert a line feed, somehow, perhaps via a character insertion.
    Code:
    fprintf(f, "%d,%f\n", Universe.year, Universe.R);
    Is the proper means to exit a loop an if then statement containing the term "break"?
    There isn't just one way to exit a loop.
    Code:
    bool someCondition = true;
    for (int i = 0; i < someValue  && someCondition; ++i)
    {
        if ( I_want_to_exit_early)
        {
            someCondition = false;
            continue;
        }
    }
    or
    Code:
    for (int i = 0; i < someValue; ++i)
    {
        // if the loop needs to terminate prematurely
        if ( I_want_to_exit_early )
            break;
       //...
    }
    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Feb 2005
    Posts
    34

    Re: Two Questions - Return at end of paired data points in CSV file, and how to "brea

    Got the line feed to work by adding \n after the float output formatting code. Still need to verify the "break" from loop solution.

  4. #4
    Join Date
    Feb 2005
    Posts
    34

    Re: Two Questions - Return at end of paired data points in CSV file, and how to "brea

    Thanks for the "break"!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center