I want to read from a filestream for z bytes. Then I want to give the value in a char array back. I would appreciate it if you could give me an explaination. That's my code since now:
char * getData(FILE * fp, long * x)
{
int z = 0;
char * data = malloc(sizeof(char) * BUFFLENGTH);
strcpy(data,"");
while(z < BUFFLENGTH-2)
{
if(feof(fp) == 0)
{
data[z] = fgetc(fp);
z++;
x++;
}
else
{
strcat(data,"\0");
return data;
}
}
}
I know that the segmentation fault is triggered threw this line:
data[z] = fgetc(fp);
But I dont know why.