Implementation of exercise 1-9: copying and printing input text to output, removing redundant spaces.
This commit is contained in:
parent
7be84d6b88
commit
7d26e0ffc7
1 changed files with 28 additions and 0 deletions
28
KNR C/ex1_9.c
Normal file
28
KNR C/ex1_9.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
|
||||
int a = getchar();
|
||||
int state = 0;
|
||||
|
||||
while (a != EOF){
|
||||
|
||||
if (state == 1){
|
||||
if (a != ' '){
|
||||
putchar (a);
|
||||
}
|
||||
} else {
|
||||
putchar(a);
|
||||
}
|
||||
|
||||
if (a == ' '){
|
||||
state = 1;
|
||||
} else {
|
||||
state = 0;
|
||||
}
|
||||
|
||||
a = getchar();
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue