getline.3: EXAMPLE: specify file to be opened as command-line argument

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2017-01-23 15:31:08 +13:00
parent 71fd04a347
commit cbc616e345
1 changed files with 7 additions and 2 deletions

View File

@ -165,14 +165,19 @@ They were standardized in POSIX.1-2008.
#include <stdlib.h>
int
main(void)
main(int argc, char *argv[])
{
FILE *stream;
char *line = NULL;
size_t len = 0;
ssize_t nread;
stream = fopen("/etc/motd", "r");
if (argc != 2) {
fprintf(stderr, "Usage: %s <file>\en", argv[1]);
exit(EXIT_FAILURE);
}
stream = fopen(argv[1], "r");
if (stream == NULL)
exit(EXIT_FAILURE);