String-length of an multi-dimensional array
Hi,
How is it possible to get a string-length of an multi-dimensional array? I need it to reallocate memory for an array that's meant to store strings, each in their own individual element. My current alternative is to use malloc() but this does no good - I'm getting segfaults...Here's my code:
Code:
File *file;
int h,i,j,fileSize;
if(!(file = fopen(FILENAME, "r"))) exit(1);
fseek(file,0,SEEK_END);
fileSize = ftell(file);
fseek(file,0,SEEK_SET);
char *readString = malloc(fileSize+1);
fread(readString,fileSize,1,file);
fclose(file);
char **lines = (char **) malloc(strlen(readString+1));
i = j = 0;
for (h=0;h<fileSize+1;h++) {
if (readString[h] == '\n') {
i++;
j=0;
}
else {
lines[i][j] = readString[h];
j++;
}
}
Any help largely appreciated. Thanks.