From the course: C Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unformatted I/O example

Unformatted I/O example - C Tutorial

From the course: C Standard Library

Start my 1-month free trial

Unformatted I/O example

- [Instructor] In this code I have already included stdio.h which is the header file that contains the functions we are interested in. As you can see in the main function, we have two variable definitions, one character c and one string str of length 20. Now I will write some code for an echo application which will take in a single character and print that character out and then it will take a string of characters and print that string out. So writing the character echo is quite simple. As you can see in line 6, you just have to assign to c the result of getchar. Next, printing out the character is just as easy, you just have to call putchar and send the character as an argument. That's it for the character echo. Now before we get to the string echo, I have to take care of a lingering character, which is a newline character that came in when I hit Enter at the time the character was typed in. I can do that by calling getchar and discarding it's return value. Next, let me separate the…

Contents