Added program to display datatype info.
[C-Programming-Examples.git] / ex_1-17.c
blobfefb535b88b1387dbfb4f84fce2c6b1a13c9d85e
1 /*
3 function: readbuffer
4 read chars from input until newline is found or buffer is full
5 return if buffer overflowed while filling
8 function printline
9 print buffer passed in
10 keep printing input until newline is found
13 main
15 buffer
16 status
17 while status not changed
18 readbuffer
20 if status changes
21 print buffer
22 print rest of line until newline
25 #include <stdio.h>
27 #define MAX 81
29 int readbuffer(char *buffer)
31 int i = 0;
32 char c;
34 while(i < MAX)
36 c = getchar();
37 if (c == EOF) { return -1; }
38 if(c == '\n') { return 0; }
39 buffer[i++] = c;
41 return 1;
44 int printline(char *buffer)
46 int endfound = 1;
47 char c, i;
48 for(i = 0; i < MAX; ++i)
49 putchar(buffer[i]);
51 while(endfound == 1)
53 c = getchar();
54 if (c == EOF) { endfound = -1; }
55 else if (c == '\n' ) { endfound = 0; }
56 else { putchar(c); }
58 putchar('\n');
59 return endfound;
62 int main(void)
64 char buffer[MAX];
65 int status = 0;
67 while (status != -1)
69 status = readbuffer(buffer);
70 if(status == 1)
71 status = printline(buffer);
73 return 0;