Hello everyone. My name is a Atharva and we are continuing with this C programming course.….. In this video we will continue with the practical session, we will start, the first practical which we will perform that will be how we can print a string on our terminal. As it is we have completed this practical early on but here we will be approaching it in a different way and we will see how easily we can print a string on our output screen or on the terminal. So, we will quickly go into our text editor and we will see their which all lines or steps we can write because of which we can print the given string on our terminal. So, to start any C program, the first line which starts or initialises, our program that is one preprocessor command line, in which we have to import one some or the other file with the preprocessor command and the stand alone file is stdio.h which helps us in performing input and output operations, in this particular practical we have to perform input and output. So, we will use such a preprocessor commands which we call as #include stdio.h, we will start with it and here we have already written #include stdio.h preprocessor command. Now, after writing the preprocessor command, do I need to make any function over here? Because I'm only printing a string over here. So, according to me, I don't need to make any function over here. I don't need to write any function definition. I don't need to declare any function. Along with this, I just have to print a string on my terminal. I will not be making any structure and neither union so that is why straightaway we will start with our main function. So, we will directly come to the main function and we all know that before the main function, we write the function’s definition or structure but here we don't require those things. The programme is completely straight. So that's why we will directly come to a main function. And we all even know that in our C program, before main function if you write any program but in the main function, if your home dosent have a main door, then no matter how big a house you make, no matter how beautiful you make it. You will not be able to go inside that house. Because you have not made the main door or the main entrance of your house. In the same way if in our program also, if we don't make the main function then we will not be able to use the program anywhere. That's the reason why making the main function is very necessary. And the main core of the program is always there in the main function. So even here, we will get our main function. This is our main function it will be of integer type. So, we have written int main over here. Now we all know that in our main function there is also a body because inside that as well we have to write few things. And those things, will be written in which area and in how many parts. Who will be defining that? That is defined by the curly brackets, the scope is defined by the curly brackets that from where our main function will start and where will it end at. So, it is very important to write it over here. Before adding anything in the main function, we should add curly brackets it is very necessary. So, we have put here curly brackets that's why we will also put the curly brackets over here. So now we have also put the curly brackets over here. Now is the time that what should we write in the main function with which we can print our string or our sentence on the terminal, as an output we can show it. So, we had read that if we want to print anything on our terminal then we make use of a function, with the help of the function we get it printed and that function’s name is printf function. What does the printf function do? It helps us to print anything on the terminal. And what are we doing here? We are getting a string printed over here. So, we all know that inside the printf function, the round brackets which are there. Inside that in double quotes, we write the things over here which we wish to show as an output on our output, terminal screen. Here if I want to print my string I will use my printf function that's why we even get our printf function over here. So, you can see that we have used a printf function and in the double quotes we have written one string, we have written one sentence which says that “Printing a demo string on to the terminal.” Here on the terminal we are trying to print one demo string of which we are making a program. So, this was about our printf function. Now our main intention to make this program, what was it? It was to print a string and we can see that it is getting completed over here. We are not finding any shortfall in our program, which means there is the printf function over here and it is even written in the main function. And since we have to perform both input and output, so here we have also imported the stdio.h file. So, all the things are complete over here. There is nothing that is left in our program. But if you see carefully, here when we had started the main function by our curly brackets in that, whatever things we had to write after that, we even have to close it, if we make the house and we don't make the walls, which means we don't close it from any sides. That house will not look like and house. It will look like something else which is just open. So, if we want to close it, so that we can use things in it. So, then we will have to make the walls. We'll have to close it because of which it will be called as house in the same way, if we have given the main function, the main door. We have started with our curly brackets, we'll even close it with our curly brackets. Now we will put our curly brackets over here. So, this entire program of printing the string has got complete. It is ready to run, everything is set in it. We have put all the ingredients in it, now's the time is to run it and see. Now what we will do here quickly. The program is already saved. We will right click and click on run code. What will happen here, you can see this, that it is still getting executed. So, it is telling me that your code has an error, so we will see what exactly is the error. Here it is saying expected identifier and round brackets before curly bracket token. Okay, so I guess that there is no mistake over here. But sometimes our compiler behaves abnormally, so what will we do in this? We will run this manually in the terminal and see. So here the string print.c that is there. This is in which folder, it is there in the practicals folder like you can see it, and that practical folder is there in the C folder. So first I will go into the C folder over here. So, I have gone to the C folder with the help of cd command. The cd command is basically command prompt command. These we will explore more that which all things we have to do. If we have to see anything inside the folder, now all these things we can explore. Here I just have to go inside my particular folder. Which means, I have to go into my practicals folder. Then I will use cd command over here which will help me to go inside that particular folder. So, here we have come into the practicals folder. And now we will try to run it. So, here we will write the file’s name as “stringprint.c” and we will execute it with the help of gcc. So, here it has got executed now what we will do this, now we will run it. So, I pressed any character and as soon as I press Enter, you can see that the string has been printed on our terminal. Now what is it saying here? Printing a demo string onto the terminal. The string that we wished to print that exact same to same have been printed over here, which means that our program has been completed successfully. We saw the reasons why we have to use these things. If we want to print some strings is there a need for functions here or not? Is there a need to make structures or not? Do we have to use if else or not? Do we have to use loops, so all these things we saw here that there is no need to use any thing. Because this was a simple programme. We just had to print a string over here. That's why we made the main function. And inside that we wrote a printf function and we printed a string over here. So, this was our practical in which we saw how to print a string. If you think that there is any part of this video or this topic, you might have not understood then you can ask us any query or question related to that topic without any inhibition.
You just have to go on forums.learnvern.com,
you have to type your query there in your own language and we will
come up with the solution or the answer as soon as possible in your own language.
Apart from this if you wish to have a discussion on any topic.
Even that you will be able to do on forums.learnvern.com.
In the same way, we will be seeing the next videos with different types of practicals. Where we will learn the approach of swapping the two numbers. Now this problem statement is not easy to understand while listing to it. Swapping the two numbers means what exactly. Solving one particular problem. With the help of our C programming function and functionalities still time thank you so much.
Share a personalized message with your friends.