linux - Is it necessary to write a "portable" if (c == '\n') to process cross-platform files? -
this thinking comes discussion practical problem replacing multiple new lines in file one . wrong happened while using cygwin terminal running on windows 8.1 machine. since end-of-line terminator different, \n , \r , or \r\n , necessary write "portable" if(c=='\n') make work on linux, windows , os x? or, the best practise convert file commands/tools? #include <stdio.h> int main () { file * pfile; int c; int n = 0; pfile=fopen ("myfile.txt","r"); if (pfile==null) perror ("error opening file"); else { { c = fgetc (pfile); if (c == '\n') n++; // work fine under different platform? } while (c != eof); fclose (pfile); printf ("the file contains %d lines.\n",n); } return 0; } update1: crt convert line endings '\n'? if input file opened in binary mode (the character 'b...