Created
July 5, 2013 01:55
-
-
Save EdgeCaseBerg/5931197 to your computer and use it in GitHub Desktop.
Simple program to take an input from the stdin and spit it to stdout on a single line without any duplicate whitespace. Not as efficient as it could be, but quick and dirty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
main(){ | |
int c; | |
while((c = getchar()) != EOF){ | |
if(c == '\n'){ | |
putchar(' '); | |
while((c = getchar()) == '\n') | |
; | |
if(c != ' ' && c != '\t') | |
putchar(c); | |
continue; | |
} | |
if(c == '\t'){ | |
putchar(' '); | |
while((c = getchar()) == '\t') | |
; | |
if(c != ' ' && c != '\n') | |
putchar(c); | |
continue; | |
} | |
putchar(c); | |
if(c == ' '){ | |
while((c = getchar()) == ' ') | |
; | |
putchar(c); | |
} | |
} | |
//Move curser down | |
printf("\n"); | |
//Use ctrl+D on unix systems to output an EOF to stdin | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run it: