6 function: discard newline
7 for loop through buffer looking for terminator
8 if current postion is newline, set position to terminator
12 for find end of buffer as integer
14 for loop reverse through string printing out chars one at a time
19 for get chars until buffer is full
20 if last char is newline add to end of buffer
21 terminate buffer with '\0'
42 convert newlines into nulls marking end of array
45 int discard(char buffer
[])
48 for(i
= 0; buffer
[i
] != '\0'; i
++) /* loop until we find NULL */
50 if(buffer
[i
] == '\n') { buffer
[i
] = '\0'; } /* convert newlines into NULL */
58 loop through buffer reversing chars
61 int reverse(char buffer
[])
65 for(j
= 0; buffer
[j
] != '\0'; ++j
) { } /* find length of buffer */
66 --j
; /* move back one space */
68 /* loop though length of array reversing front to back chars */
69 for(i
= 0; i
< j
; i
++)
72 buffer
[i
] = buffer
[j
];
82 get input passed to program and store in buffer
83 check along the way that the input has not run out
84 do this until we reach a newline and then terminate with NULL
87 int getline(char buffer
[], int limit
)
91 for(i
= 0; i
< limit
- 1 && (c
= getchar()) != EOF
&& c
!= '\n'; ++i
)
96 if(c
== '\n') { buffer
[i
++] = c
; }
98 buffer
[i
] = '\0'; /* terminate string at this position */
100 return i
; /* return number of chars found in this line */
107 while(getline(buffer
, sizeof buffer
) > 0)
109 // printf("getline\n");
112 printf("%s\n", buffer
);