Hi to all, I have a text file and i want to to read it line by line and put the lines into an array.
The snippet behind gives error while compiling:
FILE *f;
char line[LINE_SIZE];
char *lines;
int num_righe;
f = fopen("spese.dat", "r");
if(f == NULL) {
f = fopen("spese.dat", "w");
}
while(fgets(line, LINE_SIZE, f)) {
num_righe++;
lines = realloc(lines, (sizeof(char)*LINE_SIZE)*num_righe);
strcpy(lines[num_righe-1], line);
}
fclose(f);
The error is:
spese.c:29: warning: assignment makes integer from pointer without a cast
spese.c:30: warning: incompatible implicit declaration of built-in function ‘strcpy’
spese.c:30: warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast
Any help? Thanks