How do i print escape characters as characters?

前端 未结 4 843
闹比i
闹比i 2020-12-20 02:17

I\'m trying to print escape characters as characters or strings using this code:

while((c = fgetc(fp))!= EOF)
{
    if(c == \'\\0\')
    {
        printf(\"          


        
4条回答
  •  遥遥无期
    2020-12-20 03:03

    For that we need to use double backslash.

    Examples:

    if(c == '\0')
    {
        printf("   \\0");
    }
    else if(c == '\a')
    {
        printf("   \\a");
    }
    else if(c == '\b')
    {
        printf("   \\b");
    }
    else if(c == '\f')
    {
        printf("   \\f");
    }
    else if(c == '\n')
    {
        printf("   \\n");
    }
    else if(c == '\r')
    {
        printf("   \\r");
    }
    else if(c == '\t')
    {
        printf("   \\t");
    }
    else if(c == '\v')
    {
        printf("   \\v");
    }
    

    Should work for you!

提交回复
热议问题