I am working on a lab assignment for the C programming class, which I take. I wrote the code in my local Cygwin directory, compiled it with gcc
, and the executable that is created works exactly the way I want, without errors.
When I copy my code to my school UNIX server and compile it with gcc
, I get no errors, but when I try to run it, nothing happens.
I tried to do gcc 2darray.c -Wall -pedantic
, and this is what was returned:
2darray.c: In function 'main':
2darray.c:5:3: warning: missing braces around initializer [-Wmissing-braces]
2darray.c:5:3: warning: (near initialization for 'M[0]') [-Wmissing-braces]
2darray.c:5:24: warning: C++ style comments are not allowed in ISO C90 [enabled by default]
2darray.c:5:24: warning: (this will be reported only once per input file) [enabled by default]
Errors mention something about array initialization M
, but I don't see any problems with the way I initialized it. Here is the code I'm trying to compile:
#include <stdio.h>
int main(void)
{
int M[10][10] = {0};
int i, j;
int sum[10] = {0};
for (i = 1; i < 10; i++)
{
for (j = i - 1; j < i; j++)
{
M[i][j] = -i;
M[i][j+1] = i;
M[i][j+2] = -i;
}
}
for (i = 0; i < 10; i++)
{
for(j = 0; j < 10; j++)
{
printf("%3d", M[i][j]);
}
printf("\n");
}
printf("\n");
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
sum[i] = M[j][i] + sum[i];
}
printf("%3d", sum[i]);
}
return 0;
}
printf for , , , - ?
, Cygwin UNIX:
0 0 0 0 0 0 0 0 0 0
-1 1 -1 0 0 0 0 0 0 0
0 -2 2 -2 0 0 0 0 0 0
0 0 -3 3 -3 0 0 0 0 0
0 0 0 -4 4 -4 0 0 0 0
0 0 0 0 -5 5 -5 0 0 0
0 0 0 0 0 -6 6 -6 0 0
0 0 0 0 0 0 -7 7 -7 0
0 0 0 0 0 0 0 -8 8 -8
0 0 0 0 0 0 0 0 -9 9
-1 -1 -2 -3 -4 -5 -6 -7 -8 1