I am getting segmentation fault with this code even though the two files are having 2^14 values each. Could anyone tell me the reason why.
#define N 128 #include<stdio.h> #include <malloc.h> int A[N][N]; int B[N][N]; int C[N][N]; void mmul(); int main() { int p,q; FILE *fp; fp=fopen("A.txt","r"); if(fp=NULL) printf("Error\n"); printf("A"); for(p=0;p<(1<<7);p++) { for(q=0;q<(1<<7);q++) { fscanf(fp, "%d", &A[p][q]); } } fclose(fp); fp=fopen("B.txt","r"); if(fp=NULL) printf("Error\n"); for(p=0;p<(1<<7);p++) { for(q=0;q<(1<<7);q++) { fscanf(fp, "%d", &B[p][q]); } } fclose(fp); printf("here"); mmul(); } void mmul() { int i,j,k; unsigned int sum; for(i=0;i<N;i++) { for(j=0;j<N;j++) { sum=0; for(k=0;k<N;k++) { sum=sum+(A[i][k]*B[k][j]); } C[i][j]=sum; } } }
FILE *fpand your assignment, rather than evaluation-check, to NULL.