Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.9_SinBlank.c
1240 views
1
/**
2
* Exercise 1.9 - Write a Program to copy its input to its output, replacing
3
* each string of one or more blanks by a single blank.
4
*
5
* */
6
7
#include<stdio.h>
8
9
#define NONBLANK '-'
10
11
int main(void)
12
{
13
int c, lastc;
14
15
lastc = NONBLANK;
16
17
while((c = getchar()) != EOF)
18
{
19
if(c == ' ')
20
{
21
if(lastc != ' ')
22
putchar(c);
23
}
24
else
25
putchar(c);
26
lastc=c;
27
}
28
return 0;
29
}
30
31