← Previous lessonFree lesson 2 of 3 · lesson 2 of 68Next lesson →

Unlock all 68 lessons of Embedded Programming EssentialsFull course ₹40,000 · paid

Price & syllabus
Free lesson · 38 min · no payment

C Program Layout and Standard Input and Output Functions

A free lesson from Skill-Lync's Embedded Programming Essentials course, on Grow by Skill-Lync · Last updated 16 Nov 2026 · Session: “W1 S2 Basics of C Programming and Standard I/O Library”

What will you learn in this free Embedded Programming Essentials lesson?

The instructor recaps the toolchain and explains native versus cross compilers, then shows how to create a workspace and a MinGW GCC project. He describes the basic layout of a C program and the stdio functions getchar, putchar, printf and scanf.

  • Native compiler versus cross compiler
  • Workspace and project setup with MinGW GCC
  • Parts of a C program: preprocessor, main, comments
  • getchar, putchar, printf and scanf return values

What comes after lesson 2?

The next free lesson is lesson 3, “Installing MinGW GCC and Running a First C Program” (15 min). Later in Skill-Lync's Embedded Programming Essentials course (paid): lesson 4, W1 S3 C Datatypes,FPU,Enum & Typedef; lesson 5, W1 S4 Operator Precedence & Associativity; lesson 6, Week 2 Session 1. The full course has 68 lessons (34 h 47 min of video); see the course overview or its price and syllabus.

Lesson transcript

Machine transcript of the lesson audio (lightly cleaned). Technical terms may contain errors; the video is the reference.

Hello everyone. As part of this lecture, we will discuss about C-Language input and output function. When I say input and output, how do you read the data from the user and how do you send the data back to the user? Everything is going to happen through the console. Now, in today's topic, we will discuss about some of the standard functions offered by C-Language for performing this. So, a quick recap to our previous topic. So, in our previous discussion, we discussed like what is an embedded system?

When we say embedded system, it is the combination of hardware and software dedicatedly built up for a special purpose. We saw the traditional definition of embedded system and some of the key traits and characteristics of an embedded system. And how does an embedded system architecture altogether look like? And what is the typical requirement of embedded hardware? And what is the typical architecture of the embedded software? These are the introduction to embedded topics we have discussed on. Then we discussed about why C-Language is considered as a preferred language for embedded software development.

What are the features we have in C-Language, which makes it more comfortable for the programmer to use it along with embedded system development? Then we figured out how to set up a toolchain. So, in our case, we have selected Eclipse-based IDE, which is an STM32Cube IDE. Then we selected our compiler as GCC compiler, which comes along with GDB, which is GNU debugger and much more tools. So, we will try to use those tools whenever it is required as part of this course. And we also attempted to create a new project.

So, these are the topics that we have discussed in our earlier slide. Now, one thing we have to see, the STM32CubeID contains a cross-compiler by itself. When I say cross-compiler, it is going to generate executable that is running on a target platform or that is going to run on a target platform, something like STM32NucleoBoard or STM32F477Es or some particular series of our family of microcontrollers. But here, we are attempting, or in this course, we are attempting to build our executable, which will run in our host PC.

So, if we have our host PC, my executable should run on this host PC. So, how do I generate or how do I compile and produce this executable, which runs on host PC? For that, we require the compiler that's other than the cross-compiler, which I call it as a native compiler. So, for that reason, we went ahead and we installed GCC in our previous session. Hope this is clear. Host compiler, host compiler is what native compiler means. The difference between native compiler and the cross-compiler is very important when it comes for embedded application development.

Now, let me show you the various steps that is involved in the STM32 IDE for creating a new project or creating a code to run for first time. So, the very first step is setting up your workspace. You have to create a folder. Workspace is nothing but a folder in your hard disk. So, this folder is going to contain or this workspace may contain multiple projects. So, each project in turn will contain or you can assume it is going to contain project 1, project 2, project 3.

Each project in turn will contain multiple files, multiple .c, multiple .h files together. This is how the arrangement will look like. So, once you have selected your workspace, the second step is to create a new project. It is very mandatory to create C or C++ project. Let's not choose STM project at this level because we are trying to create an application that is going to execute on the host PC. This is very, very important. Then, you can either choose a C managed build or C++ managed build.

Then, start creating an empty project. And, very importantly, please choose MinGW GCC compiler. So, automatically you will see this MinGW GCC compiler popping out here if you have successfully installed your GCC compiler. Please don't select either of Cross compiler, Cross GCC or MCU ARM GCC. As far as this course is concerned, we will try to use MinGW GCC throughout this course for creating all of our applications that is running on the host PC. Now, let me go ahead and open STM32 and create a new project.

So, just open your cube IDE. The very first step it is going to ask is creating a workspace. Now, let me go ahead and create a workspace in my desktop, not even desktop, in my embedded folder. So, let me create a embedded workspace and go ahead and launch. For the first time, this may take a while. If it takes you to some of the help pages, just go ahead and skip and close this information. And, center updates and go ahead and click new. So, here you have to choose CRC++ project.

And, just go ahead and choose C++ manage build. Then, choose a empty project and choose MinGW GCC. The project that you are going to create will be inside your directory or will be inside your working space. So, I am creating a project called as Hello World. So, just go ahead and click next. And, let's make it as executable type on the tool chain. Please do ensure that it is MinGW GCC. So, once you created this project, you could be able to see the project, empty project explorer, as project file in the explorer this side, and which will have some of the editor files that is included.

So, this portion is what is called as Project Explorer, or this entire window is called as Project Explorer. So, here you will have your editor or this place. When you open up any .c file, the editor pops up here. And, when you compile the program, you could see all the warnings and errors under this problem description. And, all the user interface will happen through this particular console. And, the outline of the program can be visualized in this outline window. If you have bigger program, which is divided into multiple functions, the outline of those functions can be listed here, so that you can easily traverse in a very large number of file.

And, it also offers other tools, such as Build Analyzer and Static Analyzer. This is to visualize how your function call stack is happening, and you can see memory regions, memory details. So, we will be widely using this when we are coming into the embedded C development. So, as of now, for host environment development, let's not worry about this part. But, let's go ahead and create a new file in this particular project. So, I am creating a new file. So, very importantly, you have to choose C source file.

And, I am giving the file name. So, it should always end with a C. Or, else it will show you an error. File name is discouraged. File extension is need for understanding the file types. So, just go ahead and give C. So, that it will create you a C template of this. And, go ahead and write your first program. Let me try to write a very quick program and show you how to execute it. So, I am going to write a small program, which is going to interact with my output console and produce an output.

So, once you have written this code, just go ahead and save this. And, then to compile it. So, there are multiple options doing it using this toolbox. So, let me teach you a very normal process using which you can build a code. So, if you have one single file under a project folder, I recommend you to... Right-click this file and choose build selected files. If you have multiple files together and you want to compile it, right-click the project folder and build the entire project. So build is a process which is going to create you the executable for the program that you have written.

Now let me go ahead and build the selected file. Internally, it is performing this particular GCC command and it is creating the object file. In turn, it is going to create a executable. When the linker starts running, it is going to create the executable. Once the executable is created, you could be able to see the executable available in this path. Just go ahead and click build project. Now you could see the binaries got generated, which means there is an object file that got generated and linked via the linker.

And this is a allow world exe. So usually an executable is created for the entire project and the project is subjected to have one main function, which is going to serve as an entry point. Now once you have created this binary, let's go ahead and run this. This is a very important step. So when you are attempting to run the application, let me make sure that you are using this. Let's not use this one. We have to see the output is running and seeing it as a local C or C++ application.

Why? Because again, we are reinforcing the same point. We are creating the C code for the host PC, not on the STM32 for any other target. To run the output, you just have to, as I told you, you just have to choose this. And so you will see the output in the respective console. If at all you have any errors, you will be seeing that here. I'll deliberately create an error and I'll show you. If you go ahead and build this project, you could see some error, which is the token is missing.

And if you see the error item is declared here. And in your outline, you can able to see all the function that got declared inside this code. So as of now, we have only main function, which is returning integer. So this is how you create your first program and you successfully compile to see an output in the console. Hope this is clear. So this is a very similar program that I have shown. For your reference, you can watch this or pass at this moment and you can do this code and you can try executing your code and see what is the output that you are getting.

So this is what I was attempting to explain. So this is a place which is Project Explorer where you will find multiple C files and projects. And it will help you to navigate between multiple files. In case if you are generating any executable, you can see that. And this is a place where you go and edit and the console and problems. And this is for analyzing the code outline. And this is for seeing the function call flow and for analyzing the build code. So this part, let's not worry on this moment.

So if still you feel that you are facing some issue in generating the file, first, I recommend you to clean the project. If you have attempted something wrongly, just go out and clean the project, which will remove all the binaries. To clean the project, you are recommended to right-click the directory and go out and clean project. This would remove all the generated exe so that you can generate the exe once again freshly. Now let's see about the actual topic for this session, which is the input-output console part.

First, we will take a C program and we will dissect this and see what are the important elements we have in a C program. Then we will figure out how the layout of C program should be. Then we will come to the standard Ivo library, which we are including in our program as stdivo.h. It stands for standard input and output library. Then we will discuss some of the standard character-related functions such as putcar and getcar. Then we discussed the output function, standard output function, which is helping us to send value to the console with the help of printf and sprintf.

Then we will discuss about how do you read from the console from the user using scanf and a scanf. So our learning objective for this session would be understanding the stdio-related functions and understanding how to use the IDE and how to bring up write your first C program and create executable for our host machine. At this point, everybody should have got an idea how to create an executable for a host machine. If not, pause this video here. Go back and repeat the exercise of successfully building the hello world.

Still, if you pertain any of the problem, go ahead and delete it, restart the IDE and clean the project and start everything freshly. Because there are certain steps, if you are making any mistakes on that particular steps, you will end up in creating a different executable that may not be suitable to run in a host machine. Now, we will look at some of the basic elements that forms our C program. One is called as preprocessor. The very first line that we see in our program that is called as preprocessor, which starts with the indication hash.

So this is helping us to include the already existing programs and libraries. Sorry, which means already the compiler designers had created an enormous amount of programs which can be reused by us. Even printf, which we used in our earlier example to print the statement allowed, it was a code or it was a program which was actually existing in a library. So, the very first line helps you to link all your external programs which were already existing. Then, you need to have variable definitions, variable declaration. And you also need to have function definition, function declaration.

Then, you need to have one of the key part which is your entry point, your main function. So, if a program is having only one function, always that needs to be main. Without having a main function, we cannot able to create a valid C program with an entry point. As I told you, then we need to have proper key statements and expression. Then, we need to have comments very neatly written because this is going to make your code much more readable. When I say comments, these are non-executable part of your program.

So, there are two ways of commenting your program in C language. You can put a double slash in this direction and you can write your comments. This is called a single line comment. So, any piece of code which is starting with this line will not be considered by your compiler for execution. Similarly, you can have multiple lines of comments starting with slash and asterisk and ending with asterisk and slash. So, this will help you to do multiple lines of comments. Always make sure that when you do multiple lines of comments, you are not commenting the proper code which needs to be executed.

So, this encompasses your basic elements of a C program. Function, declaration, main function, keywords, statements, expression, comments. Then, you need a preprocessor and variables. Now, let us take one C program and we will dissect it for its layout. So, any program should start with this kind of multi-line comment explaining who is the author and what is the program written for. So, ideally, it needs to contain information like author and objective. This is a very well followed practice and a very detailed comment and when it is created, by whom it is created.

So, all those things, please add it on the beginning of the program. This is what I name it as comments. So, these lines will not be considered by your compiler when you compile the program. Then, the line that is starting with ash is called as preprocessor section. All the existing code or the prior code to link it, we need to do this preprocessor. We need to include those codes in the preprocessor section. Then, we have our global section where we can go ahead and declare a function or declare a variable.

Let us not worry at this moment if you do not understand what is a function and what is a variable. We will see one by one. Then, you need to have your entry point which is the main function and inside your entry point, you need to have the local variable declaration and your actual definition. In my case, Yes. My actual definition is a console input-output statement. Then if you are attempting to call other function, you can have the calling function. Then you can have the called function definition separately, which is called a subroutine or subfunction.

Usually we use this function for reusing certain portion of code again and again. This is a typical layout of any C programming. Now let's go and see what the standard input and output library is offering to us. So the standard input and output library is what we call it as stdio.h, which is already included in our code. It helps us by offering different IO-related operations such as printf, scanf. All these functions are defined in stdio.h. Now we will try to apply one console-related function, the GETCHAR, which operates on a single character.

So it reads a character stream. When I say stream, a sequence of characters that is coming from the console. Or a continuous sequence of characters that is coming from a console. So we will read the character stream from the console. Then putcar is going to write a character stream onto the console. And we also have this special library called a ctype.h. This is going to help us to offer some more functionality, some more special functionality. And I would like the participants to go ahead and see what are different functions that is offered by ctype.h.

So one of the functions that I have used is to convert all the characters that I am streaming in my console to uppercase. So this program, as I told you, it is including two libraries or two preprocessors. So this is going to offer certain reusable code. And this library is going to offer me certain reusable code. And when I started executing this code, it will enter into the main function. Then I am just going ahead and creating a variable or reading a variable till I reach my end of statement.

Let's go ahead and run this program and see. So I have already used this program. Yeah, now I will just go ahead and build the project again. If you have this kind of issues, when you run that as a local application, it should pop out something like this. Now, this code is expecting me to enter a code or to enter a character stream. I am just giving the character stream as skill-link. And this oil loop would be continuously executing till I pass the EOF. So in my case, my EOF is going to be terminate.

Let's go ahead and run this again. So previously, I used a character, a hyphenide. I think that fails to convert it into an uppercase letter. So now the code is working as expected. We are reading a stream of character. And when I pass the EOF by just clicking this terminate button, you could be able to see it is again putting the code back into the console by converting it into an uppercase character. So this function is actually helping me to read the character by character. Whereas this function is trying to put the character by character to the console.

This is coming from console. This is putting back to the console. Writing to the console. Now we will see what is wrong with this code. This code and try what is wrong with the code. The same code is written here. So just pass the video here and try executing this similar code or try executing the similar code without a while loop. So even though the get character is continuously getting the character, you can keep on entering the stream. But ideally, it would have read only the first character.

Why? Because the get char and put char is designed to operate on a single character. Now let's go ahead and discuss print of and sprint of functions. So print of is a function that is defined in stdio.h library. And it is going to help perform an operation of printing a data to console. Other than this, it will also help me to convert the data like as I wish. Let's say if I want to see a data as a character. If I want to see a data as an integer.

I have a provision of converting that type part by the usage of formatting. So there is something called as format specifier in my print of statement or in my print of function. This will allow me to see the data as I wish. That's possible. So even if you have a character data, you can see that as an integer. If you have an integer data, if you want to see that as a decimal number, still you can go ahead and see. Or if you have a decimal number, you can go ahead and see that as an integer.

It is up to you to specify what format of data that you want to put the given data in the console. So it is a typical function signature or a prototype. Every print of statements will have a return value. And that return is of type integer. Most of the times, people would have often used print of statement. It is used for its purpose of writing a data to the console. But inherently or indirectly, it is doing other tasks. It is returning an integer. Let's have a look what this integer is.

And you have to specify the format first, then followed by the arguments. So print of as a pitfall, which we will discuss in our upcoming lectures. There is no mandatory restriction that this character format should match with this argument list. When I say you can have three arguments and you can have two character format. So that is not considered as an error. Rather, it is considered as a warning. We will take that as a pitfall of the print of function that we can discuss in our upcoming lectures.

Now, this is how a typical print of statement will looks like. It is formulated by a character array or character sequence. Then your format specifier. Then your actual variable, which is my argument. So I'm interested to see the value of C in my console in percentage C format, which indicates it's a character. And this text or this character array would be directly printed onto the console. Now, what are different formats specifiers that the C language is offering? It offers percentage D, percentage C, percentage X, percentage O, percentage F to see the values in different, different forms.

Percentage X will help you to get the value in X, hexadecimal, percentage O in octal. Even percentage P will be helpful for you to see the data and if it is a pointer address or if it is address of a memory location, percentage LD, you have percentage U, you have two for and same data. So there are much more format specifiers. Here we are using few format specifiers and trying to print a different variety of different formats of values. At this moment, if you don't understand anything about this, these keywords, let's not worry.

Just go ahead and try this program and see how you can format your data and you can see that in different, different format of the console. Which means I'm going ahead and printing an integer value when the same value printed as a character, it's equivalent ASCII value is printed here. So now again, I'm printing 80, the character equivalent of that is P. So I'm trying to print a hexadecimal value equivalent of 66, which is 42. So this would be very interesting and useful feature when we use to do some sort of printing.

Let me go ahead and explain what this return value of printf statement. So when this printf got executed successfully, it returns a type int, which means it is returning a integer value. So when I say returning, the output of this function to the program is what call it as or what we call it as a return value. To the console, it is the actual string that we are trying to do. But to the back to the program, it is returning an integer. That integer value represents the character count of the statement that got printed into your console.

Let's say, for example, in this statement, I have a very huge, or let's say, for example, I have a huge set of values. I'm going ahead and I'm printing it, and when I keep a variable here to see what is the integer, it is trying to be giving me back an integer called as 27, which is nothing but the character count of this particular stream. So in this, it is including spaces, empty spaces also. Just pause the video here and go ahead and execute this program and see how this is 27.

Let's pass your own string, which has special characters, which has spaces, and which has this kind of escape sequence, which is called as escape sequence. So usually escape sequence is to create a spacing in your console output, or to produce a new line in your console output. Just go ahead, figure out how this is 27. Now, let us see one more function, which is called as yesPrintOf. So printOf is a function which is going to stream the given data into the console. Whereas yesPrintOf is a function, which is going to stream the data into a string rather than passing it to a console, which means it will be storing the data in the string that you are giving here.

So first you have to specify what is the name of the string you want to hold and what is the data that you want to stream. So the syntax is slightly different between printOf and printOf. So printOf syntax will have only this portion, whereas yesPrintOf will have a string associated with that. The first argument is the string. So I have declared that string as a character array. Every string is a character array. So even if you don't understand array at this moment, let's not worry about that.

So yesPrintOf is going to generate an output or going to store the output not in the console, rather it is going to store in an internal variable. Okay, let's consider this string as your internal variable. This would be one very useful feature when you are attempting to save the message that you want to write and you later put it in a file or something. In those scenarios, it would be very useful. So it can be considered as a internal variable as I pointed out. So just pause the video here, try to replicate this code and understand what is there stored in the internal variable A, whether you figure out any difference between the stream of character that you passed or it is the same character.

Now let's see on the other important function, which is going to help us in reading the data from the console, which is SCANF and SCANF. So SCANF is very less widely used function. So the syntax of SCANF is also similar to printOf, where I'm going to have a format specifier followed by the address of each of the argument. So this is called as a de-referencing operator or address of operator. So I'm going to read the address of each of the variable and I'm going to read the data in my own desired format.

So there in the printf, I'm trying to write the data in my desired format. Here, I'm going to read the data in my desired format. So this is the typical syntax of the SCANF function. The SCANF function is also located or written in the stdio.h. So try to do a type conversion by changing different format specifiers in the given code. And the SCANF function also return me an integer value, which is nothing but how many variables that we read from the console. In this example, I'm reading two values.

So I'm trying to see that or read that as an integer. So I'm giving my format specifier as %d followed by their addresses. Then I'm going ahead and printing those values and I'm printing what is there in my SCANCOUNT. I've entered two values. So it says my input is two. So the return value can be holded using this kind of variable. Again, by an internal variable, it has got no connection back with your console. Similarly, this SCANF is there, which is very rarely used. So SCANF will allow you to read the data and not from the console terminal, rather from the function itself.

So you can give the inputs here as a string and read those string in the respective variables. So all these are possible. If you are trying to use the character array, you need not give ampersand in front of those things. The ampersand there is not required, or I would say it's not mandatory. The reason for that we will discuss in our upcoming lectures when we are discussing more on the character array. But as of now, just understand the syntax when you use %s in printf, R, SCANF, the ampersand symbol is not necessary.

So that's what we planned for today's discussion. Let's do a quick summary. We started with how to write a code, hello world, in our tool chain. And how do we compile and build it? Then we went ahead and see how the typical C programming layout looks like. Then we figured out how to write our first C program and compile it. Then we have figured out what are different library functions that's existing and for handling our input and output pertaining to the console. Then we have seen the function like get care, put care, which operates on character by character streams.

Then we have discussed about functions like printf, scanf, and the difference between sprintf, unprintf, scanf, unscanf. Then we discussed about what is the return value that's given by a function, the printf, unscanf. So that's it for today's session. Hope the session would be clear for you. So if you have any programming queries, so just go back and pass on the respective program and try to execute the mentioned program by yourself. If you are not getting output for the first time, just go ahead and clean the build or create a new project and execute it for other time.

So before we start watching the next video, let's make yourself comfortable with using this tool because from next video, we'll be enormously spending our time in writing codes and building the code again and again. So just familiarize yourself with the compiler keys and the shortcuts so that you'll be able to do the codes very quickly from your end. Thank you.

Want the rest of Embedded Programming Essentials?

Get the full course syllabus and fees.

The full course is paid (₹40,000). We'll send the syllabus and call you back within one working day.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Full course · paid

Unlock the full Embedded Programming Essentials course

The remaining 65 lessons, mentor-reviewed projects and a certificate come with the paid course (₹40,000). Leave your details: we'll send the syllabus and fees and call you back.

Get the syllabus and fees

A counsellor calls you back within one working day.

By submitting you agree to our Terms and Privacy Policy.

Grow by Skill-Lync · free lesson

Start watching

Free, no payment. Leave your details once and every free lesson on Grow plays straight away. A Skill-Lync counsellor may call you about the full Embedded Programming Essentials course.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.