Created
June 14, 2015 18:41
-
-
Save apfohl/73f829d4e27a27cb2d40 to your computer and use it in GitHub Desktop.
getline example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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