解决方法
当你因为某些原因不能使用fgets()时,这应该是有效的.
int readline(FILE *f,char *buffer,size_t len) { char c; int i; memset(buffer,len); for (i = 0; i < len; i++) { int c = fgetc(f); if (!feof(f)) { if (c == '\r') buffer[i] = 0; else if (c == '\n') { buffer[i] = 0; return i+1; } else buffer[i] = c; } else { //fprintf(stderr,"read_line(): recv returned %d\n",c); return -1; } } return -1; }