Im writting a socket-based program that connects to a server, which sends a continous stream of data through a TCP socket... Which I which to read line-by-line.
Now what is the best way I can read each line of this stream?
I've thought of something like:
Or is there some other way, because memory usage could get very high if a new line never comes?
char * line;
unsigned long int totalSize = 0;
/* while we're getting data */
while(recv(sock, &c, 1, 0) > 0)
line = realloc(totalSize);
/* add c to line */
/* check for new line */
Thanks in Advance