문제

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