Thread: Don't know why this is happening

  1. #1
    Unregistered
    Guest

    Question Don't know why this is happening

    I'm just in the beginning stages of my code and already I'm in trouble.
    The part that I'm working on is supposed to read a map into a 2d array, and I wanted to print out the array to see if I got the whole thing.
    However, when I print it out, I get everything except for the half of the last line.

    Here is my code so far:
    #include <stdio.h>

    #define MAXROW 50
    #define MAXCOL 100

    main ()
    {
    int Row_Num, Col_Num;
    char Map[MAXROW][MAXCOL];
    char Moves[50];
    int ctr_Row, ctr_Col;

    scanf ("%d %d", &Row_Num, &Col_Num);
    if ((Row_Num<=MAXROW)&&(Col_Num<=MAXCOL))
    {
    printf ("%d %d\n", Row_Num, Col_Num);
    for (ctr_Row=0;ctr_Row<Row_Num;ctr_Row++)
    for (ctr_Col=0;ctr_Col<Col_Num;ctr_Col++)
    scanf ("%c", &Map[ctr_Row][ctr_Col]);
    for (ctr_Row=0;ctr_Row<Row_Num;ctr_Row++)
    for (ctr_Col=0;ctr_Col<Col_Num;ctr_Col++)
    printf ("%c", Map[ctr_Row][ctr_Col]);
    printf ("\n");
    printf ("%d %d", ctr_Row, ctr_Col);
    }
    return 0;
    }
    and when I run the prog, the counters all come out correct, so what gives? Any help is greatly appreciated.
    Thanks

    Doug

  2. #2
    Unregistered
    Guest
    oh, and sorry about the formatting, I thought the indentations would come out.

    Doug

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    42
    Code:
    #include <stdio.h> 
    
    #define MAXROW 50 
    #define MAXCOL 100 
    
    main () 
    { 
       int Row_Num, Col_Num; 
       char Map[MAXROW][MAXCOL]; 
       char Moves[50]; 
       int ctr_Row, ctr_Col; 
    
       scanf ("%d %d", &Row_Num, &Col_Num); 
       if ((Row_Num<=MAXROW)&&(Col_Num<=MAXCOL)) 
       { 
          printf ("%d %d\n", Row_Num, Col_Num); 
          for (ctr_Row=0;ctr_Row<Row_Num;ctr_Row++) 
             for (ctr_Col=0;ctr_Col<Col_Num;ctr_Col++) 
                scanf ("%c", &Map[ctr_Row][ctr_Col]); 
             for (ctr_Row=0;ctr_Row<Row_Num;ctr_Row++) 
                for (ctr_Col=0;ctr_Col<Col_Num;ctr_Col++) 
                   printf ("%c", Map[ctr_Row][ctr_Col]); 
                   printf ("\n"); 
                   printf ("%d %d", ctr_Row, ctr_Col); 
       } 
    
       return 0; 
    }
    http://www.KBeutler.com

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    all the characters I entered in printed out, the very first scan which reads the array dimension to use, is that meant to be inclusive, ie I put in "2 3" and entered 3 characters where as I would assume it should be 6 characters. If this is the problem you mean, then in the for statements that read:

    Code:
    for (ctr_Row=0;ctr_Row<Row_Num;ctr_Row++) 
             for (ctr_Col=0;ctr_Col<Col_Num;ctr_Col++)
    change it to

    Code:
    for (ctr_Row=0;ctr_Row<=Row_Num;ctr_Row++) 
             for (ctr_Col=0;ctr_Col<=Col_Num;ctr_Col++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Explain me what is happening
    By capvirgo in forum C Programming
    Replies: 2
    Last Post: 02-18-2008, 08:26 AM
  2. Something funny happening with operator overloading
    By Argyle in forum C++ Programming
    Replies: 8
    Last Post: 04-14-2007, 04:59 PM
  3. Rounding Float- Return not happening ?
    By pprabhakar in forum C Programming
    Replies: 5
    Last Post: 05-14-2006, 09:44 AM
  4. Why is this happening?
    By caduardo21 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2005, 01:09 AM
  5. Weird things happening!!!!!!
    By korbitz in forum Windows Programming
    Replies: 4
    Last Post: 03-22-2004, 06:31 AM