Y
yo_mismo
Hi everyone,
I'm trying to read the first line of a file this way:
....
....
....
....
new_line=0;
while((read=read(fd, &info, sizeof(info))) > 0 && !new_line){
if (strcmp(&info, "\n") != 0){
strcat(line,info);
}
else{
new_line=1;
}
}
But i can't find the end of the line and this code goes until the end of the
file instead the end of the line.
The other problem is that i get a segmentation fault in strcat(line, info),
i've declared the variables like this:
char *line="";
char info;
That's all, i hope someone can help me 'cause i can't find the errors.
Thanx.
I'm trying to read the first line of a file this way:
....
....
....
....
new_line=0;
while((read=read(fd, &info, sizeof(info))) > 0 && !new_line){
if (strcmp(&info, "\n") != 0){
strcat(line,info);
}
else{
new_line=1;
}
}
But i can't find the end of the line and this code goes until the end of the
file instead the end of the line.
The other problem is that i get a segmentation fault in strcat(line, info),
i've declared the variables like this:
char *line="";
char info;
That's all, i hope someone can help me 'cause i can't find the errors.
Thanx.