Hello everyone, my name is (name) and we are continuing with this C programming course. (7 seconds pause, music)
In the last video we had discussed typedef function, we had seen how we can give a new name to our data type’s type, and then we saw how it is different from hash define function.
And both their functionalities, how they counter each other and how it makes our program effective So, all these things we had discussed in the last video and in this video, we are going to see a new thing, we are going to see input and output functions.
Earlier, we had seen a few inputs and output functions like printf and scanf.
These are very basic input and output functions.
But apart from these if we talk about the other input and output functions.
So, all those we will be seeing in this video.
Without any delay we will start and we will see how this input and output is done. If we talk about C programming, the C programming language treats all the devices as files.
So, our computer that is here, our screen is connected with it, our keyboard or mouse.
All these devices that are there, how does our C programming access all these? It accesses it in the form of a file.
It considers all these devices as a file itself.
And with the help of it, the method accesses our screen, when we have to show any output on our screen or I have to take any input from the keyboard.
All these things are considered as a file by the C programming.
Apart from that if we say few files automatically gets opened when a program executes to provide access to the keyboard and screen.
So, when we open one C program, we make it or run it.
At that time automatically there are few files like we were talking about our devices that are there like screen or the keyboard.
So, these files that are there, are considered as a file by the C programming.
So, there are few files that automatically open, so that our program can converse, and can perform input and output operations.
So, we will see these things, how these input and output operations are there.
How they are basically performed and how they are accessed to our devices, even that we will see.
Now we will go ahead and we will see that the file pointers are the means to access the file for reading and writing purposes.
So, here I talked about our devices, since we are considering them as a file.
So, how we will access the file, we will access the file with the help of file pointer, like I said that our pointers are basically storing the addresses.
So, our file pointers also store any address of the files.
Which means here the files are our devices.
So, the keyboard would be stored on whichever device, on whichever port the keyboard would be connected or there would be any type of information.
That basically will be stored by our file pointer in itself.
And our C program will converse with the file pointer in that way and will perform input, output operations.
So, these file pointers are of different types.
We have listed here 2 basic file pointers, which is our standard input and standard output.
So, this input and output functionality is being provided.
So, these are the pointers basically that we are discussing here, which is called STDIN, which is for input and STDOUT, standard output, for the output.
Here you can see that STDIN is used for the keyboard as we are giving input through the keyboard.
Along with that STDOUT, is used for our screen, as we are giving our output here.
So, we don’t have to type these file pointers manually.
This is typed by our C program automatically; it opens it and it accesses that particular file or device and then it takes the input in the program and processes it and one more file of that type, which is our monitor in this case, at that monitor with the help of STDOUT it provides it and the monitor displays it over there The backend functionality or the backend story that is there, we tried to understand it, how the file pointer is made by our C program and when the C programs made by this pointer and then we are able to converse with our devices or files.
5:01
So, this was about how we are conversing.
Now, what all are the functions of conversing and what all are the ways that we are discussing over here.
First, we are discussing two input and output functions.
Their names are getchar (pronounce- get care) and putchar (pronounce- put care).
So how are these functions? With their English names we will get to know basically what their work will be.
So, here if you would see getchar, so getchar basically, if we try to understand it in English, it is saying that get the character, character as we know is a single alphabet basically, we can also say that it can be a number, it can also be any symbol, but it will remain single.
So, in the same way we have to get the character, which means we have to get it in our program.
So, that's why we will be inputting it.
So, this getchar function that is there is basically used to input the character in our C program.
Apart from this if we talk about putchar function.
So, what is putchar basically, it is putting the character.
Put means put it on the output or display it.
So, basically the functionality of getchar (get care) is to take the input and the functionality of putchar (put care) to put the character or to display it.
So, we will practically use it and see quickly how their functionality would be working.
And here there is one more thing to pay attention to, in the getchar function.
In its round brackets, there are no parameters, it is blank.
But if we talk about our putchar function, in that we give one variable in which variable the character is stored, that character is displayed on the screen by the putchar function.
So, we will go on to our text editor and we will quickly see how this getchar and putchar functions are helpful for us.
7:05
So, here we have come onto our programming screen, which is our text editor.
If you read the first line, this is our preprocessor command.
Then we will come to our main function.
Here if you can see we have made one C variable and it is of integer type.
Then we have used a printf statement, which is demanding to take an input of a character inside.
From whom? From the user.
So, in the printf we have said Enter a character and here you will see how the getchar function is used.
You can see in the getchar function that in its round bracket there are no values.
There is nothing.
So, what will getchar do? It will pick one character from our input and whatever output or return getchar will give, that will be saved in the C variable.
So, in getchar (get care) whichever character has come from our keyboard that has been stored in C.
So somewhat in this way our getchar works, if we move ahead now, we are printing over here, the character that we had typed which character was that? So, we have stored it in C.
So now we will use putchar (put care) and in the parameter of putchar parameter or in the round brackets.
We will put that variable in which that character was stored and as soon as we complete this getchar or putchar, our program will also get over here.
In this program what we did was we took a character from the user and we printed that same character and gave it back.
8:30
So, this was about our code and now we will run it and we will see how its output comes.
So, here there is one more thing to pay attention to.
When I will be typing you see at that time, okay.
Here what I have typed, LEARNVERN, here I have typed learnvern but it is telling me that I have to type a character itself.
So, no matter how long a sentence I write, it will consider only one single character, the first character that will be in your sentence, like in this case it is L, so it will consider only L.
So, we will see how it will do that.
Here I have written Learnvern but since we are using getchar and he wanted one single character, that's the reason why it is thinking that he will take only one character from it.
So, the first that you have typed, that getchar will take.
So, now we will enter, now you can see that your character is L, here it took L only inside it.
Rest of the line or sentence went to waste.
Getchar only reads one single character.
So, in this way the getchar (pronounce - get care) and putchar (pronounce- put care) works when we are performing input and output operations.
Apart from these there are two more such functions which help in performing input and output functions.
So, let's see which are those functions.
So, those are get-s (pronounce- get S) and put-s (pronounce - put S) functions.
Like, what getchar used to do.
It used to take the input of the character and what putchar used to do, it used to give the output of the character, in the same way get-s takes the input of a string basically.
And if we talk about put-s, it prints the string in the output.
So, these are the functionalities of get-s as put-s.
10:20
Here you can even see the syntax that in get-s also there is a parameter, along with that even in put-s there is a parameter.
So, the get-s function reads a line from STDIN.
Which means our standard input pointer, from there basically our string reads and along with that it is also saying that until the end of the file or new line is encountered.
So, what it is trying to say here, till the time we don't leave one single line and move to the new line or our line doesn't get over, till that time get-s keeps taking input of the string.
Along with that if we talk about put-s, this function writes the string to STDOUT, which means it prints on the standard output.
Now we will see its functionality with a practical example.
So, we will quickly understand how it will handle strings as well.
So, here we'll come into our get-s code.
So here we have made one simple code.
We will be starting with the preprocessor command which is our standard input, output dot h file.
This is what we have imported over here.
After that we have come to our main function.
And what we did in the main function.
We made a string named CH, which was of size 100.
And how did we get to know that we have made a string? Because if you see its data type that is char (pronounce - care).
And we have learned that string’s data type is char (pronounce - care).
And for the rest of the arrays, there can be any data type.
So, here I have made one string and what did I print? I said enter a text now.
So, first I was saying enter a character.
But here I am saying that you write any text and our get-s will take that text inside, it means basically it will take a string.
So, whatever will be our CH limit or size which is 100 over here, that many characters it will take inside of him.
Here after the printf statement we have put one get-s function.
If you see in its parameter, you will see that I have passed the name of the string, which is ch over here.
The string in the ch is going to get saved.
It will be saved till when, till the time its size is not 100 that is full.
So, get-s (pronounce- get S) has taken the string inside of it.
Now the time comes to print that string.
So, here we will again print ‘you entered’ and in the next line whatever will be printed in front of it that would be with the help of the put-s function.
Our strings which were stored in ch, that will be there.
So, you can see here that we had taken the string input from get-s and with put-s we are giving the string output, which was stored in CH.
So, this is a simple program where getchar (pronounce - get care) and putchar (pronounce - put care) was used and after that get-s and put-s has been used here.
Even this we will execute and see, we'll run it and see, what is the output that we will be getting.
Here it is telling me to enter a text, so here we will write a simple text.
13:14
We will not write an exhaustive one.
So, here I have written one text,... qwerty learnvern, so this is my string and text.
Right? Now I will click enter.
So, you can see that my qwerty learnvern, my entire sting basically, get-s has taken it in through STDIN pointers and after that it is stored in CH.
It was stored in the string and with the help of put-s function, it again printed it on our output screen.
So, this was about our input and output functions, getchar, putchar, get-s and put-s function.
So, here we saw that getchar and putchar, deal with the characters and get-s and put-s deals with the strings.
So, we have seen these inputs and outputs function in today’s video.
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 click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
We will meet in the next video where we will be discussing how to handle the files and how to perform input and output operations on them.
Till that time, thank you so much.
Share a personalized message with your friends.