File tree 1 file changed +8
-7
lines changed
1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 15
15
#include <stdio.h>
16
16
#include <string.h> /* for strlen() */
17
17
18
- #define BUFSIZE 100
19
- #define MAXLEN 10000
18
+ #define BUFSIZE 100
19
+ #define MAXLEN 10000
20
20
21
21
/* functions */
22
22
int getch (void );
@@ -45,22 +45,23 @@ void ungetch(int c)
45
45
/* ungets: push back s onto the input */
46
46
void ungets (char s [])
47
47
{
48
- int len ;
48
+ int i ;
49
49
50
- for (len = strlen (s ) - 1 ; len >= 0 ; -- len )
51
- ungetch (s [len ]);
50
+ for (i = strlen (s ) - 1 ; i >= 0 ; -- i )
51
+ ungetch (s [i ]);
52
52
}
53
53
54
54
/* test ungets */
55
55
int main (void )
56
56
{
57
57
int c , i ;
58
- char s [MAXLEN ];
58
+ char s [MAXLEN ];
59
59
60
- printf ("Enter string to test ungets function: " );
60
+ printf ("Enter string to test ungets function:\n " );
61
61
for (i = 0 ; (s [i ] = getch ()) != '\n' ; i ++ )
62
62
;
63
63
s [i ++ ] = '\n' ;
64
+ s [i ] = '\0' ;
64
65
ungets (s );
65
66
66
67
while ((c = getch ()) != EOF )
You can’t perform that action at this time.
0 commit comments