failure to print characters+values from an array with a nested loop how I want it to

This is a discussion on failure to print characters+values from an array with a nested loop how I want it to within the C Programming forums, part of the General Programming Boards category; This code comes from a programming assignment that is no longer current from my class. I've already talked with the ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    1

    failure to print characters+values from an array with a nested loop how I want it to

    This code comes from a programming assignment that is no longer current from my class. I've already talked with the instructor, but it's still bothering me though that I couldn't get this version to work completely right. This one also has in my opinion an aesthetically better intended output then what I ended up with.
    I've seemed to corner the issue down to a nested loop in the program.

    I'm not sure how much of the code I should post, so I attached a copy of the c file.


    Code:
            NEWLINE;
            printf("The characters for each line and their values: ");
            NEWLINE;
    
    
            count=num;
    
    
            for(int i=0; i<num; i++){
                pChar(cArray,i);
    //printf("\nDebug: %d\n",i);
    
    
                if(i%M==0&&0!=i){
                    NEWLINE;
    
    
                    for(int j=0;j<10; j++){
                        if(count==0){
                            break;
                        }
                        pValue(cArray, (i-(9-j))); // j is used as an offset from i
    //printf("\nDebug: %d\n",(i-(9-j)));
    
    
                        notBool=1;
                        count--;
                    }
                    NEWLINE;
                }}
    
    
            if(notBool==0){
                NEWLINE;
                for(int k; k<10&&k<num; k++){
                    pValue(cArray,k);
                }}

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,640
    I see no attached file, and it's going to be very difficult for us to determine the problem because we can't see the defitions of pChar, pValue or NEWLINE, nor do we know what the output should look like (the right format) and what it currently looks like (the wrong format). Your indentation/formatting is not very good. Good, clear indentation makes understanding flow control (things like if/else and loops, especially nested ones) much easier.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding values to array in a for loop
    By bman900 in forum C Programming
    Replies: 1
    Last Post: 11-06-2010, 07:58 AM
  2. Replies: 3
    Last Post: 10-21-2010, 01:39 PM
  3. Converting Char Array Loop values to integer
    By azamsharp1 in forum C Programming
    Replies: 8
    Last Post: 10-27-2005, 10:13 AM
  4. for loop again and array values, need help
    By InvariantLoop in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 10:29 PM
  5. How do you create and print an array of characters
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 07-09-2002, 05:22 PM

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