How do i print escape characters as characters?

前端 未结 4 1681
花落未央
花落未央 2020-12-20 02:32

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

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


        
4条回答
  •  -上瘾入骨i
    2020-12-20 02:58

    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!

提交回复
热议问题