Skip to content

Commit 3397a08

Browse files
committed
fix whitespaces and add terminating char to string
1 parent 8461723 commit 3397a08

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

chapter04/4-7.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <stdio.h>
1616
#include <string.h> /* for strlen() */
1717

18-
#define BUFSIZE 100
19-
#define MAXLEN 10000
18+
#define BUFSIZE 100
19+
#define MAXLEN 10000
2020

2121
/* functions */
2222
int getch(void);
@@ -45,22 +45,23 @@ void ungetch(int c)
4545
/* ungets: push back s onto the input */
4646
void ungets(char s[])
4747
{
48-
int len;
48+
int i;
4949

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]);
5252
}
5353

5454
/* test ungets */
5555
int main(void)
5656
{
5757
int c, i;
58-
char s[MAXLEN];
58+
char s[MAXLEN];
5959

60-
printf("Enter string to test ungets function: ");
60+
printf("Enter string to test ungets function:\n");
6161
for (i = 0; (s[i] = getch()) != '\n'; i++)
6262
;
6363
s[i++] ='\n';
64+
s[i] = '\0';
6465
ungets(s);
6566

6667
while ((c = getch()) != EOF)

0 commit comments

Comments
 (0)