From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/OR_PRACTICAL_C/13_1.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 reference/C/CONTRIB/OR_PRACTICAL_C/13_1.c (limited to 'reference/C/CONTRIB/OR_PRACTICAL_C/13_1.c') diff --git a/reference/C/CONTRIB/OR_PRACTICAL_C/13_1.c b/reference/C/CONTRIB/OR_PRACTICAL_C/13_1.c new file mode 100644 index 0000000..4f44233 --- /dev/null +++ b/reference/C/CONTRIB/OR_PRACTICAL_C/13_1.c @@ -0,0 +1,30 @@ +#include +#define FILE_NAME "input.txt" +#include /* ANSI Standard C file */ + +main() +{ + int count = 0; /* number of characters seen */ + FILE *in_file; /* input file */ + + /* character or EOF flag from input */ + int ch; + + in_file = fopen(FILE_NAME, "r"); + if (in_file == NULL) { + (void)printf("Can not open %s\n", FILE_NAME); + exit(8); + } + + while (1) { + ch = fgetc(in_file); + if (ch == EOF) + break; + count++; + } + (void) printf("Number of characters in %s is %d\n", + FILE_NAME, count); + + (void) fclose(in_file); + return (0); +} -- cgit v1.2.3-54-g00ecf