hey, this is supposed to collect data into a 2 by 3 array. believe it or not, my teacher wrote this problem and he spent 20 minutes trying to figure out why it wasn't running properly. anyone care to help me figure out what was wrong with it??

#include <stdio.h>

int main () {
    int scores[2] [3];
    int row =2, col=3;
    int i, j;
for (i=0;i<=row;i++){
     for (j=0;j<=col-1;j++){
         printf ("enter number");
         scanf ("%d", scores[i] [j]);
     }
}
printf ("\n", scores [i] [i]);
return (0);
}

lines 7 and 8 are incorect. Array elements are counted from 0 up, but not including the max index number. For example scores has valid index values of scores[0][] and scores[1][] The <= operator on line 7 will attempt to dereference scores[2][], which does not exist.

The correct code for line 7 would replace <= with just <.

line 10 is also in error. You have to pass a pointer to scores by adding & pointer operator. scanf("%d", &scores[i][j]);

Edited 5 Years Ago by Ancient Dragon: n/a

Even though AD explained the problem, I have to add to it:

hey, this is supposed to collect data into a 2 by 3 array. believe it or not, my teacher wrote this problem and he spent 20 minutes trying to figure out why it wasn't running properly. anyone care to help me figure out what was wrong with it??

Given that explanation, what are we supposed to be looking for? "...why it wasn't running properly" means what? What is unproper about it? What are we looking for?

"...what was wrong with it??" depend on what it's doing.

When you need help, please explain what we're looking for, why you claim it's not working. It really saves us from guessing.

its collecting the data, but it is not putting it into the array, nor is it printing the array

sir found the error about a week ago..sad to say i lost the finished program

sir found the error about a week ago..sad to say i lost the finished program

Man! Isn't that bad luck? Just when you found the error, you lost the program. Life ain't fair.
I'm glad you found the Internet, though! ;)

Edited 5 Years Ago by Aia: n/a

This question has already been answered. Start a new discussion instead.