Skip to content

Instantly share code, notes, and snippets.

@zihengCat
Last active September 9, 2017 01:15
Show Gist options
  • Save zihengCat/88c9cb025505f44419130e88e9dddf23 to your computer and use it in GitHub Desktop.
Save zihengCat/88c9cb025505f44419130e88e9dddf23 to your computer and use it in GitHub Desktop.
Text file format convert
#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;
}
#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