fgets read file line with "\n" inside

Hi,

I have a string like this,

char str[] ="This, a sample string.\\nThis is the second line, [\\n](file://\\n) [\\n](file://\\n), we will have one blank line";

if I want to use strtok() to seperate the string, which token should I use?

I tried "\n", "[\\n](file://\\n)", either not working.

peter

You realize that fgets() stops at a newline, yes? You can't read multiple lines with it.

If that's supposed to be the letters \ and n, not a newline, then strtok() won't work on that either: strok needs single characters as separators, tell it to split on "\\n" and it will split on | or n.

---------- Post updated at 04:58 PM ---------- Previous update was at 04:52 PM ----------

How about this:

#include <stdio.h>
#include <string.h>

int main(void)
{
        char str[] ="This, a sample string.\\n"
                        "This is the second line, \\n"
                        " \\n"
                        ", we will have one blank line";
        char *buf=str, *tok;

        while(tok=strstr(buf, "\\n"))
        {
                tok[0]='\0';
                tok[1]='\0';
                printf("<%s>\n", buf);
                buf=tok+2;
        }
        printf("<%s>\n", buf);
        return(0);
}