title: Get row and column number from file C
body: <p>i have a .txt file I want to read from in C. Every character should be a col and every line a row.
  I want to store the number of rows and columns in an int variable.
  I did it like this. My rows numbers are correct, but my columns are 0.</p>
  
  <pre><code>...
  
  int rows_i = 0;
  int cols_i = 0, cols = 0;
  
  FILE* file = fopen(file_name, "r");
  
      if (file) {
          while ((c = fgetc(file)) != EOF) {
              if (c == '\n') {            
                  break;
              }else if (c !='\0') {         
                  rows_i++;
              } else {
                  cols_i++;
                  if(cols_i&gt; cols){
                      cols = cols_i;
                      cols_i = 0;
                  }
              }
          }
      } else {
          printf("No such file!");
          return ...;
      }
  ....
  </code></pre>
  
  <p>Any idea why that is?</p>
  
  <p>My output of rows is correct. Output for cols is always 0.</p>