Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- /* Collapse spaces:
- * Write a program that reads all input and prints it transformed as
- * follows:
- • any sequence of whitespace that does not contain newline is
- replaced with a single space character
- • whitespace characters immediately before a newline are deleted.
- */
- void collapseSpaces(){
- char a = ' ', b;
- while((b = getchar()) != EOF){
- if((isspace(b) == 0) || (b == ' ' && isspace(a) == 0) || (b == '\n')){
- printf("%c",b);
- }
- a = b;
- }
- }
- int main(){
- collapseSpaces();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement