Use of a While Loop

This is a discussion on Use of a While Loop within the C Programming forums, part of the General Programming Boards category; Hi guys, I need some help with a while loop in the context of my system ... Code: int row ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    19

    Use of a While Loop

    Hi guys,

    I need some help with a while loop in the context of my system

    ...
    Code:
    int row = 0;
    int column =0;
    
    
      for (i = 0; i < m; i++)
      {
    
    	for (j = 0; j < inputs[i]; j++)
    	{
    	  printf("\nRow: %d\n", row);
                      printf("\tGate: %d, Input Element: [%d][%d]: ", position, row, column);
                              scanf("%d", &matrix[row][column]);
    
    	row++;
    	}
    
    	position++;
                }
    
    column++;
    ...
    The system populates the the first Row with the values the user has specified, it starts at [0][0] and the depending on how many input values, will continue to increment down the row, ie;
    [0][0]
    [1][0]
    [2][0].

    This is where I am stuck, once it has finished with the that particular row, I want the system to ask the user if they wnt to increment the column numbr and start the whole process again. Populating the thr row elements with values for the new column, i,e;
    [0][1]
    [1][1]
    [2][1].

    I hope this makes sense, I know the code is weakly coded, but that is not my concern, it is to get the column to increment while resetting the Row increementer back to 0 for eah time the column ++.

    Thank you all in advance,

    Archie

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Sounds to me like you should put the while loop in a function by itself, passing a pointer to "inputs" if necessary, and then have a parameter to indicate the column number (or the inputs pointer could be adjusted first). Then you can reuse the function to do whatever column you want.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 11:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 03:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 01:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM

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