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

Recommended Answers

All 7 Replies

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

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

Post current code.

sorry about the late reply, my internet was down >.>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.