#include <stdio.h>
#include <string.h>
/* if line is completly blank (all white-space) returns 1, otherwise returns 0*/

int blankLine(FILE *fp){
  int ch;
  fpos_t file_pos;
  fgetpos(fp, &file_pos); /*store cursor position of beginning of line*/
  
  while(1){
    ch=fgetc(fp);
    
    if(!isspace(ch)){
      fsetpos(fp, &file_pos); /*reset cursor position*/
      return 0;
    }
    
    if (ch=='\n'){
      fsetpos(fp, &file_pos); /*reset cursor position*/
      return 1;
    }
    
  };
}

int main(int argc, char**argv) {
  FILE *f;
  char buf[1024];
  int ln = 0;

  if (argc < 2) return 1;

  f = fopen(argv[1], "r");
  if (f == 0) {
    perror("fopen"); return 1;
  }

  while(1) {
    int r = blankLine(f);
    char * nl;

    if (fgets(buf, 1024, f) == 0) break;
    nl = strrchr(buf, '\n');
    if (nl) *nl = '\0';
    printf("line %u: %s (%s).\n", ++ln, r ? "blank" : "nonblank", buf);
  }

  return 0;
}
