/* * GNU patch can handle \r or \r\n line ending. It just cannot handle mixed case. * Convert ending to \r or \r\n */ #define _CRT_SECURE_NO_DEPRECATE #include #include //buffer sizse, also the maximum charactor per line #define BUFSIZE (4*1024*1024) int main(int argc, char** argv) { char *buf; int usedSize = 0; buf = (char*)malloc(BUFSIZE); while ( fgets(buf, BUFSIZE, stdin) != 0) { int len = strlen(buf); len --; while (len >= 0) { //scan string in reverse direction //remove any '\r' or '\n' from file if (buf[len] == '\r' || buf[len] == '\n') { buf[len] = 0; } else { break; } len --; } //let C lib generate a line ending puts(buf); } free(buf); }