Hi.
I'm beginner with C and I'm having problem with the following source code:
Code:
/*****************************************************************************************************/
main()
{
unsigned int lin=10;
unsigned int col=5;
unsigned int i,j;
double *grid;
double x;
grid=malloc(col*lin*sizeof(double));
if(!grid)
{
printf("Err\n");
exit(1);
}
for(i=0;i<lin;i++)
{
for(j=0;j<col;j++)
{
x=pow(i+j,2);
*(grid+(i*col+j)*sizeof(double))=x;
}
}
for(i=0;i<lin;i++)
{
for(j=0;j<col;j++)
{
printf("%10.7f\t",*(grid+(i*col+j)*sizeof(double)));
}
printf("\n");
}
/*****************************************************************************************************/
It works nice for smaller lin and col but returns "segmentation fault" if them becomes lage.
I'm using gcc 4.2 with linux kernel 2.6.22.
Thanks.
PS I'm beginner in english language as well... :P