Last active
September 9, 2017 01:15
-
-
Save zihengCat/88c9cb025505f44419130e88e9dddf23 to your computer and use it in GitHub Desktop.
Text file format convert
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 <stdlib.h> | |
int main(int argc, char* argv[]) { | |
FILE *fp; | |
if (argc != 2 || | |
(fp = fopen(argv[1], "r")) == NULL) { | |
perror("File opening failed"); | |
return EXIT_FAILURE; | |
} | |
int c; | |
while((c = fgetc(fp)) != EOF) { | |
if(c == '\r') { | |
/* skip */ | |
} else { | |
putchar(c); | |
} | |
} | |
if (ferror(fp)) { | |
fprintf(stderr, "I/O error when reading\n"); | |
} | |
else if (feof(fp)) { | |
/* End of file reached successfully */ | |
} | |
fclose(fp); | |
return 0; | |
} |
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 <stdlib.h> | |
int main(int argc, char* argv[]) { | |
FILE *fp; | |
if (argc != 2 || | |
(fp = fopen(argv[1], "r")) == NULL) { | |
perror("File opening failed"); | |
return EXIT_FAILURE; | |
} | |
int c; | |
while((c = fgetc(fp)) != EOF) { | |
if(c == '\n') { | |
printf("\r\n"); | |
} else { | |
putchar(c); | |
} | |
} | |
if (ferror(fp)) { | |
fprintf(stderr, "I/O error when reading\n"); | |
} | |
else if (feof(fp)) { | |
/* End of file reached successfully */ | |
} | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment