I\'m working on writing a IRC bot in C, and have ran into a snag.
In my main function, I create my socket and connect, all that happy stuff. Then I have a (almost) i
TCP doesn't offer any sequencing of that sort. As @bdonlan already said you should implement something like:
recv from the socket into a bufferrecv, check if the bytes received contain an \n\n use everything up to that point from the buffer (and clear it)I don't have a good feeling about this (I read somewhere that you shouldn't mix low-level I/O with stdio I/O) but you might be able to use fdopen.
All you would need to do is
fdopen(3) to associate your socket with a FILE *setvbuf to tell stdio that you want it line-buffered (_IOLBF) as opposed to the default block-buffered.At this point you should have effectively moved the work from your hands to stdio. Then you could go on using fgets and the like on the FILE *.