Thread: Use of a While Loop

  1. #1
    Registered User
    Join Date
    Feb 2009

    Use of a While Loop

    Hi guys,

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

    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]);
    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;

    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;

    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,


  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    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, 10:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 12: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