How do i print escape characters as characters?

前端 未结 4 1685
花落未央
花落未央 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条回答
  •  清酒与你
    2020-12-20 02:59

    Escape the slashes (use " \\a") so they won't get interpreted specially. Also you might want to use a lookup table or a switch at least.

    switch (c) {
    case '\0':
        printf("   \\0");
        break;
    case '\a':
        printf("   \\a");
        break;
    /* And so on. */
    }
    

提交回复
热议问题