Why do I get errors in my code only if I save the file in C-Free? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Why do I get errors in my code only if I save the file in C-Free?

I have a c program that runs if I copy the code and paste it into an unsaved file but gets 10 errors if I save and name the file. I am using C-Free.
What is going on?

For those wondering, need to print a 30X30 array of random numbers.
Compute the sum of the first row and print it.
Compute the average of the diagonal and print it.
Count the number of zeros in the first column and print it.
If I remove the "srand" line. The errors disappear and the program runs, but my array is no longer random and is just a set of fixed values.

Language - C
#include
#include
#include

int
main (void)
{

srand (time(NULL));

int i,j,array[30][30],sum1,z;
double avg,da;

i=0;
j=0;
for(i=0;i<30;i++)
{
for(j=0;j<30;j++)
{
array[i][j]=(rand() %10);
printf("%d ",array[i][j]);
}
printf("
");
}

sum1=array[0][0]+array[0][1];
for(j=2;j<30;j++)
{
sum1=sum1+array[0][j];
}
printf("
The sum of the first row is %d
", sum1);

avg=array[0][0]+array[1][1];
for(i=2;i<30;i++)
{
avg=avg+array[i][i];
}
da=avg/30;
printf("The average of the main diagnoal is %.2lf
", da);

z=0;
for(i=1;i<30;i++)
{
if (array[i][0]==0)
z++;
}
printf("There are %d zeros in the first column
", z);
return (0);
}


Errors:

--------------------Configuration: mingw2.95 - CUI Debug, Builder Type: MinGW (Old)--------------------

Checking file dependency...
Compiling C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c...
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:11: parse error before `int'
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:14: `i' undeclared (first use in this function)
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:14: (Each undeclared identifier is reported only once
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:14: for each function it appears in.)
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:15: `j' undeclared (first use in this function)
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:20: `array' undeclared (first use in this function)
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:26: `sum1' undeclared (first use in this function)
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:33: `avg' undeclared (first use in this function)
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:38: `da' undeclared (first use in this function)
[Error] C:UsersSherifDocumentsSchoolYear 1CPS 125Assignment 2.c:41: `z' undeclared (first use in this function)

Complete Make Assignment 2: 10 error(s), 0 warning(s)
Sign In or Register to comment.