Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 618 Bytes

exercise4-7.md

File metadata and controls

25 lines (20 loc) · 618 Bytes

Exercise 4-7

Write a routine ungets(s) that will push back an entire string onto the input. Should ungets know about buf and bufp, or should it just use ungetch?

Process

This is pretty straightforward. It can just use ungetch for every char in a string.

As zer0325 points out ungetch does the same thing a routine using buf and bufp would be doing anyway.

Code

void ungets(char s[])
{
    int i = 0;
    do {
        ungetch(s[i]);
    } while(s[i++] != '\0');       
}

Output

No Output

Back to Main