Copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. - C Data Type

C examples for Data Type:char

Description

Copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\.

Demo Code

#include <stdio.h>

int main(void){
    int c;/* w w  w .java2s.co  m*/

    printf("Input some characters, then press Ctrl+D.\n");
    
    while ((c = getchar()) != EOF){
        if (c == '\t')
            printf("\\t");
        else if (c == '\b')
            printf("\\b");
        else if (c == '\\')
            printf("\\\\");
        else
            printf("%c", c);
    }
    return 0;
}

Result


Related Tutorials