Thread: Output problems with structures

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    The problems seem to occuring within your PrintExp() function. Note that you declare the variable "res" in this function and initialise it to 0. You then try to use a for loop to print the Result heading which iterates from 0 to < res (which is zero at this point). Essentially this;

    for (r = 0; r < res; ++r)

    does nothing as the first time this is evaluated res is not less than 0 (it is equal to zero) and thus the code continues without iterating through this loop.

    Now the next problem is that when you don't enclose the appropriate code within braces, only the first line following the for loop is executed. So even if "res" was set to an appropriate value it would only execute the following lines of code the appropriate number of times, and everything else just the once:
    Code:
         for (r = 0; r < res; ++r)
              printf("\n\t\t");
    In order to fix the issue with the value of "res", I would recommend either passing the value of res to the function itself or incorporating a counter containing the number of results for each experiment in one of your structs.

    Also - you should not use fflush(stdin), this is undefined. You can use something along the lines of:

    while( getchar() != '\n' );
    Last edited by foniks munkee; 12-16-2002 at 05:32 AM.
    "Queen and huntress, chaste and fair,
    Now the sun is laid to sleep,
    Seated in thy silver chair,
    State in wonted manner keep."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Have a few minor problems trying to finish this program
    By kisiellll in forum C Programming
    Replies: 4
    Last Post: 02-22-2009, 07:00 PM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  4. Dialog LB output problems.
    By curlious in forum Windows Programming
    Replies: 3
    Last Post: 10-21-2003, 11:55 AM
  5. Minute Program output problems
    By Cobalt in forum C++ Programming
    Replies: 12
    Last Post: 10-12-2003, 10:16 AM