J
jan247
hi, im new here... um, this code works except that, at the end of the
loop, i always get a "Segmentation fault". Can anyone help me on this?
using GNU C:
.....
FILE *fp;
fp = fopen("./prg.c", "r");
char *line;
int x=1;
int nbytes = 100;
while(getline( &line, &nbytes, fp ) != -1)
{
printf("%d: %s", x, line );
x++;
}
fclose(fp);
.....
loop, i always get a "Segmentation fault". Can anyone help me on this?
using GNU C:
.....
FILE *fp;
fp = fopen("./prg.c", "r");
char *line;
int x=1;
int nbytes = 100;
while(getline( &line, &nbytes, fp ) != -1)
{
printf("%d: %s", x, line );
x++;
}
fclose(fp);
.....