I have the following C code which gives an error:
Program stopped at 0x4019b3.
It stopped with signal SIGSEGV, Segmentation fault.
when debugging.
Here is the code:
#include <stdio.h>
#include <complex.h>
#include <stdlib.h>
#include <time.h>
int main()
{
clock_t begin, end;
double time_spent;
begin = clock();
int n = 100;int i; int j;
int N = 64;int r;
double complex (s)[4] = {-1-1*I, -1+1*I, 1-1*I, 1+1*I};
double complex symbol[n][N];
for (i=0; i<n; i++){
for (j=0; j<N; j++){
r = rand() % 4;
symbol[i][j]=s[r];
}
// Now add pilots:
symbol[i][11] = 1;
symbol[i][22] = 1;
symbol[i][33] = 1;
symbol[i][44] = 1;
}
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
return 0;
}
Any idea what's wrong?
EDIT:
Now I can put it all together after these valuable discussions. Here is the working code with timing and memory allocation and every thing:
#include <stdio.h>
#include <complex.h>
#include <stdlib.h>
#include <time.h>
int main()
{
clock_t begin, end;
double time_spent;
begin = clock();
int n = 100000; int i; int j;
int N = 64;int r;
double complex (s)[4] = {-1-1*I, -1+1*I, 1-1*I, 1+1*I};
double complex (*symbol)[N] = malloc(n * sizeof *symbol);
for (i=0; i<n; i++){
for (j=0; j<N; j++){
r = rand() % 4;
symbol[i][j]=s[r];
}
// Now add pilots:
symbol[i][11] = 1;
symbol[i][22] = 1;
symbol[i][33] = 1;
symbol[i][44] = 1;
}
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%3.7f\n",time_spent);
return 0;
}