I'm writing a program that is essentially emulating the linux GET command, which will return a msg that contains a file and the header separated by \n\n inside the message. The only thing is I'm not sure how to search the returned string and find this message, because \n signifies that a string has ended. If anyone can help lead me on the correct path that would be awesome.

有帮助吗?

解决方案

In C, assuming you are talking about zero terminated strings (the norm), \0 (i.e. the NUL character, i.e. a zero) indicates a string has ended, not \n.

You can search for two \n using the strstr function. From the man page:

   #include <string.h>

   char *strstr(const char *haystack, const char *needle);

So something like:

char *found;
found = strstr (string_to_search, "\n\n");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top