title: Checking a character to be a newline
body: <p>How to check whether a character is a newline character in any encoding in C?  </p>
  
  <p>I have a task to write my own <em><strong>wc</strong></em> program. And if I use just if <code>(s[i] == '\n')</code> it has another answer than original <em><strong>wc</strong></em> if I call it to itself.<br>
  Here is the code:    </p>
  
  <pre><code>typedef struct
  {
      int newline;
      int word;
      int byte;
  } info;
  
  info count(int descr)
  {
      info kol;
      kol.newline = 0;
      kol.word = 0;
      kol.byte = 0;
  
      int len = 512;
      char s[512];
      int n;
  
      errno = 0;
      int flag1 = 1;
      int flag2 = 1;
      while(n = read(descr, s, len))
      {
          if(n == -1)
              error("Error while reading.", errno);
  
          errno = 0; 
  
          kol.byte+=n;
          for(int i=0; i&lt;n; i++)
          {
              if(flag1)
              {
                  kol.newline++;
                  flag1 = 0;
              }
  
              if(isblank(s[i]) || s[i] == '\n')
                  flag2 = 1;
              else
              {
                  if(flag2)
                  {
                      kol.word++;
                      flag2 = 0;
                  }
              }
              if(s[i] == '\n')
                  flag1 = 1;
          }
      }
      return kol;
  }  
  </code></pre>
  
  <p>It works fine for all text files, but when I call it to file I got after compiling itself it  does't give the answer <em><strong>wc</strong></em> gives. </p>