printing values loop.

This is a discussion on printing values loop. within the C Programming forums, part of the General Programming Boards category; I am printing out values in a for loop for(i = 0; i<value[0]; i++) { fprintf(output,"%f\n",value[0]); fclose(output); } this prints ...

  1. #1
    Unregistered
    Guest

    Cool printing values loop.

    I am printing out values in a for loop

    for(i = 0; i<value[0]; i++)
    {
    fprintf(output,"%f\n",value[0]);
    fclose(output);

    }
    this prints data only in one column.

    but i want to print out only 10 at a time and then "\n",
    and print 10 more and so on. How would I go about doing this?

    Thankx.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Look here.. Subsitute fprintf for the print a ___ lines.

    On a side note, why are you printing the same character over and over again? I'll assume you want to do:

    for( x = 0; x < whatever_the_decimal_value_of_this_array_cell_is; x++ )

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    1

    Smile use if statements

    Hi

    You can use the if statement and a counter inside your for loop.

    For example,

    if (i==10*counter)
    {
    printf("\n");
    }

  4. #4
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Code:
    for(i = 0; i<value[0]; i++)
    {
    fprintf(output,"%f ",value[0]);
    fclose(output);
    if((i % 10) == 0)
              fprintf(output, "\n");
    }

  5. #5
    Unregistered
    Guest

    Smile

    To quzah,

    The value that is being printed to the file changes as the program is running. I want to capture all of those values in a formatted way.

    Sorry it took so long to get back to you.

  6. #6
    Akilla
    Guest

    Lightbulb Set a Flag

    for(i = 0; i<value[0]; i++)
    {
    int flag = 1;
    fprintf(output,"%f",value[0]);
    ++flag;
    fclose(output);

    if (flag==10)
    {
    fprintf(output, "\n", value[0]);
    flag =1;
    }
    }



    hope this helps...


    http://mahurshi.tripod.com/minframes.htm

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Unregistered
    To quzah,

    The value that is being printed to the file changes as the program is running. I want to capture all of those values in a formatted way.

    Sorry it took so long to get back to you.
    But if you look in the actual loop, no, it actually doesn't change. Your loop, unless you happen to be making it a lot more compilicated then you actually have it, (ie: unless inside the loop you begin changing the value that is written) it will write the same character.

    Your value may change some place in your program sure, but in that loop, all that gets written is the exact same character over and over.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Unregistered
    Guest
    quzah,

    your right. I tried the nested for loop statement and It just prints the number over and over. I guess back to the drawing board.


    thanks..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing values from Enum
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 02-16-2009, 09:28 PM
  2. Controlling variable values by printing on file
    By p3rry in forum C Programming
    Replies: 8
    Last Post: 12-17-2008, 09:09 AM
  3. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  4. stuck printing values from array
    By Guti14 in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2003, 09:56 PM
  5. 2 largest elements; -1 to stop loop
    By Peachy in forum C Programming
    Replies: 4
    Last Post: 09-16-2001, 05:16 AM

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