From 6a047d173de71046d9e10d07fcbd39bbaf9078ed Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sat, 20 Nov 2021 21:22:22 +0800 Subject: 1.17: --- 1/17.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 1/17.c (limited to '1/17.c') diff --git a/1/17.c b/1/17.c new file mode 100644 index 0000000..2797b10 --- /dev/null +++ b/1/17.c @@ -0,0 +1,34 @@ +#include + +#define MAXLEN 1001 +#define PRNLEN 80 + +int cgetline(char s[], int max); + +/* prints inputs longer than 80 characters */ +int main(int argc, char *argv[]) { + int size; + char s[MAXLEN]; + + while ((size = cgetline(s, MAXLEN)) > 0) { + if (size >= PRNLEN) + printf("%s", s); + } + + if (size == -1) { + printf("exceeded max input size: %d\n", MAXLEN - 1); + return 1; + } + + return 0; +} + +int cgetline(char s[], int max) { + int c, i; + + for (i = 0; i < max - 1 && (c = getchar()) != EOF; i++) + s[i] = c; + s[i] = '\0'; + + return c != '\n' && c != EOF ? -1 : i; +} \ No newline at end of file -- cgit v1.2.3