I wanted to know the issue in the following code. This is used to first open a file of size 800Mb to fill in the name variable and later used to access the data stored in it by reading indices from another file. The problem is that after reading and filling the array name, on accessing any element from it gives a seg fault. When the same code was tested on smaller data size, it worked. What could be the reason? The hardware on which I am running this is a 4gb RAM,32 bit linux version on intel i5 chip.
#include <stdio.h>
#define MAXINT 61578414
int main(int argc,char** argv){
printf("Starting \n");
FILE* fp1 = fopen(argv[1],"r");
FILE* fp2 = fopen(argv[2],"r");
char** name;
name = (char**)malloc(MAXINT*sizeof(char*));
char* tname;
int i = 0;
int tmp1;
//reading to fill in name
while(i < MAXINT){
name[i] = (char*)malloc(20);
fscanf(fp1,"%d%s",&tmp1,name[i]);
i++;
}
//accessing elements from name
int i1,i2;
while(!feof(fp2)){
fscanf(fp2,"%d%d",&i1,&i2);
fprintf(stdout,"%s %s\n",*(name+i1),*(name+i2));
}
}