Skip to content

Instantly share code, notes, and snippets.

@apfohl
Created June 14, 2015 18:41
Show Gist options
  • Select an option

  • Save apfohl/73f829d4e27a27cb2d40 to your computer and use it in GitHub Desktop.

Select an option

Save apfohl/73f829d4e27a27cb2d40 to your computer and use it in GitHub Desktop.
getline example
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp = fopen("file.c", "r");
char *line = NULL;
size_t linelen = 0;
ssize_t len;
while((len = getline(&line, &linelen, fp)) > 0) {
printf("%zu:%zd:%s", linelen, len, line);
free(line);
line = NULL;
}
free(line);
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment