Skip to content

Instantly share code, notes, and snippets.

@tiebingzhang
Created December 18, 2015 19:17
Show Gist options
  • Save tiebingzhang/1ab85bce4504a1122992 to your computer and use it in GitHub Desktop.
Save tiebingzhang/1ab85bce4504a1122992 to your computer and use it in GitHub Desktop.
int readoneline(char *fname){
static char line[256];
FILE *fd=fopen(fname,"r");
if (fd==NULL)
return NULL;
if (fgets(line,sizeof(line),fd)==NULL){
fclose(fd);
retrun NULL;
}
line[sizeof(line) - 1] = '\0';
pos = line;
while (*pos != '\0') {
if (*pos == '\r' || *pos == '\n') {
*pos = '\0';
break;
}
pos++;
}
fclose(fd);
return line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment