Thread: array input/output problem

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    68

    array input/output problem

    input
    --------
    00000
    11111
    01010
    11001
    00110

    all i want to do is store this in a 2d char array. my problem is the correct loop to do so. the obsticle i keep running into is the damn newline character. i put a debug statement in after my loop and im getting a ascii value 10, new line, after each row should end. the rows and columns are predefined. my output would look like this ...

    array[0][0] = char 0
    array[0][0] = ascii 48
    array[0][1] = char 0
    array[0][1] = ascii 48
    array[0][2] = char 0
    array[0][2] = ascii 48
    array[0][3] = char 0
    array[0][3] = ascii 48
    array[0][4] = char 0
    array[1][4] = ascii 48
    array[1][0] = char

    array[1][0] = ascii 10
    array[1][1] = char 1
    array[1][1] = ascii 49
    array[1][2] = char 1
    array[1][2] = ascii 49
    array[1][3] = char 1
    array[1][3] = ascii 49

    ... and so on
    can anyone help with the loop ?? i been trying with a combination of for nested loops but no luck.
    "with a gun barrel between your teeth, you speak only in vowels."
    - tyler durden

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    68
    thank you salem. your loop put me in the right direction. heres the loop the worked the way i needed it.

    Code:
    for(j = 0; j < rows; j++)
       for(k = 0; k < cols)
          while((array[j][k] = getchar()) != '\n'
             k++;
    "with a gun barrel between your teeth, you speak only in vowels."
    - tyler durden

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array problem
    By TomBoyRacer in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 11:35 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  4. Need desperate help with two dimensional array problem
    By webvigator2k in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2003, 02:28 PM
  5. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM