Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.10_TbsBlnkSpaces.c
1240 views
1
/**
2
* Exercise 1.10 - Write a Program to copy its input to its output,
3
* replacing each tab by \t, each backspace by \b, and each backslash by \\.
4
* This makes tabs and backspaces visible in an unambiguous way.
5
*
6
* */
7
8
#include<stdio.h>
9
10
int main(void)
11
{
12
int c;
13
14
while((c = getchar()) != EOF)
15
{
16
if(c == '\t')
17
{
18
putchar('\\');
19
putchar('t');
20
}
21
22
if(c == '\b')
23
{
24
putchar('\\');
25
putchar('b');
26
}
27
28
if(c == '\\')
29
{
30
putchar('\\');
31
putchar('\\');
32
}
33
34
if(c != '\t' && c != '\b' && c != '\\')
35
putchar(c);
36
}
37
return 0;
38
}
39
40