-
2D array of names
Why is it that I do not get the date printed ?
Code:
int main()
{
...
char month[][MONTHS] = {"Jan", "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec"};
...
printf("The lowest rainfall of %fmm falls in %s,\n" , lowest , month);
}
-
You've got the array declaration backwords. Should be:
Code:
char months[MONTHS][]
Next, you need to index into the array to specify which string to print, eg: months[which].
-
if you imagined accessing values stored in your your array in terms of x & y co-ordinates or across & down then it is the opposite of our usual usage, you would say 'down and across'>>
Code:
int main()
{
int myarray[4][4];
int down = 2;
int across = 2;
myarray[down][across] = 10;
printf("At 2 down and 2 across my array holds > %d\n", myarray[down][across]);
return (0);
}
-
If you're going to post code, please don't use bad practices: SourceForge.net: Implicit main - cpwiki
Also indent your code properly.
-
remembering the array starts with element 0 of course! so its actually "at three down and 3 across" if your user is counting from 1