How do i print escape characters as characters?

前端 未结 4 807
闹比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 02:52

    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. */
    }
    

提交回复
热议问题