'How can I detect an empty line in a text stream and print everything below it?
I am trying to use strcmp and fgets to read line by line to detect "\r\n". I'm working in a program with websockets and I want to show the HTML code in my console that it is written in the socket.
while( ( n = read(s, buffer, sizeof(buffer)-1) ) > 0 ) {
buffer[n] = 0;
FILE *fp = fdopen(s, "r+");
while(fgets(buffer, sizeof(buffer), fp)!=){
if (strcmp(buffer,"\r\n")==0){
fputs(buffer,stdout);
}
else{
printf("error\n");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
