Created
April 9, 2012 04:15
-
-
Save codebrainz/2341387 to your computer and use it in GitHub Desktop.
Convert newlines to \n and strip extra trailing whitespace
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> | |
| #include <string.h> | |
| #define MAXLINE 16484 | |
| int main(void) | |
| { | |
| int c; | |
| size_t len; | |
| char line[MAXLINE] = { 0 }; | |
| while (NULL != fgets(line, MAXLINE, stdin)) | |
| { | |
| if ('\0' != line[0]) | |
| { | |
| len = strlen(line); | |
| while (len--) | |
| { | |
| c = line[len]; | |
| if (c == ' ' || c == '\t' || c == '\n' || c == '\r') | |
| line[len] = '\0'; | |
| else | |
| break; | |
| } | |
| } | |
| fputs(line, stdout); | |
| fputc('\n', stdout); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment