Multiple Character Input Output Function – Data Input and Output – C Programming Language

Multiple Character Input Output Function – Data Input and Output – C Programming Language

Hello friends let’s deal with the second type of input/output functions with C language these functions which are going to discuss are going to be pertaining for multiple character input and output instructions which means that when a person comes of responding a set of characters has your answer for example when I ask your name your name will not be single character your name is going to be a set of characters when you ask your address it will be a set of characters when asked your college name it is a set of characters when such inputs are separated in that case we are supposed to deal with these functions necessary the first function that is the input function as it is said that when a input input is always from the device to the memory that is from the user it goes through memory the function which we use for this task is get s what exactly is particular gatos function does it reads a set of characters and store into the variable which is allocated for that so before you start with get as we should understand what type of variables am I supposed to use for this suppose if I define a character variable as say CH if I define a calculator versus eh this function reads only one character or stores only one character but I’m supposed to define a variable which can store a set of characters how to make this variable to store a set of characters should i define multiple variables know the answer is no because when a different multiple variables you have to use a multiple get care instructions to read this input for that what are those I’ll use multiple character variable which means a single character variable is now ready to store a set of characters by defining a character as an array as a car CH bracket I’ll put any constant of my choice let me say ten now on a sec rch of 10 this CH is no more array this CH is an array not a variable an array of ten spaces so when I say this this CH will have ten spaces to store a set of 10 characters this entire set can be called a CH but these individual locations are again referred separating the first location might be referred as CH of zero the square brackets are red as off the second bracket is red as CH of one the third location is red as CH of two and so on and so on till I reach the last location that is CH 19 for this declaration y9 even though size was 10 since my index the first number the number which you associate with the cat available we call that has index the first index is referred as a 0 hence the last index will be referred as 9 c h of 0 2 CH of nine such functions such variables should be used to use with get as a function let’s see the input operations with greatest function so the syntax goes as I should use get s and within these brackets I am super specific a character array let’s say you a simple example to illustrate this syntax I will say get s bracket suppose if character is CH of pen shall say CH which means that biscuit s is now ready to store a set of characters into a variable called as CH where CH is a character array let us see half the input goes into this particular CH I have example to say this assume that the input goes SI a b c and a hit the enter key now the variable CH is all about the Hospice’s ten spaces so these tens faces have to be used initially all these ten spaces are filled with some garbage values we call them as junk values are unknown values or garbage values so what gay testers reads this string till you hit the enter key and stores each of these characters into a character array it is true the first character into the first location the second character into the second location the third character in the third location and what it does is it will automatically append the string with a null character we call this as a string termination the character because this has escaped sequence so a string termination character or a null character the street our Venetian character or the null character is automatically added by the gators function what is the purpose of this why it is supposed to add up doona few that you consume one additional space yes as for the concepts of string null character will occupy one additional character but it plays a very important role when we try to read when we try to access this particular function basically when I read this particular contents null character is used as a differentiator to identify the valid input and the garbage values which exist in the ring anything which appears before null is always input and anything which appears after null he is going to be garbage values what if I have the input as say a B C 1 and then / 0 and hit the enter key don’t feel that if I internal character it will read that as a null character no in this case this CH will store the contents in this fashion the first character is read as a the second characteristic as be the third character is read as see the fourth you might call it as digit one but it is ultimately a character 1 / 0 is not the cat which you are going to be identifying as null character in this case it Lanford has two separate characters a slash will occupy one space 0 will occupy one more space and then a string is automatically appended again with another character so in this case the number of characters are 1 2 3 4 5 6 are the one which you have entered and null character is automatically appended with this thing so it means they’re going to define a character array with the 10 spaces it is advised to store only nine characters because one you will automatically going for null character so this is about the input function now let us do with the output function the output function which we use for this task is put s what exactly is particular function does as it is said output function which means that the value is displayed from the memory to the user whatever the contents which are stored into a character array those contents will be displayed as it is on the screen let us try an example to illustrate this particular protest function so the syntax goes as and then example as put s bracket met let me say ch when I say put SCH what it does is this contents of character SCH are displayed as it on screen one by one till it finds a null character so put s will always look out for a string da rumination character is null character till it final character it keeps on displaying character by character on the output screen so suppose if I take up the example of the first one so what put s CH goes with the first example so what could s resist it takes the first character checks whether it is null if not it will display the character on the screen so it will display a on the output screen and then it goes and takes the next character use this next character null character no displays the next character is this character null character no displays the character the next car is null character yes it stops the operation so basically put s displays the contents of character array as it is on the screen till it finds a null character so that’s it about the concepts of footage functions let us look at a program which will use Gettis as well as protest functions which are a very simple code I ask you to enter your name on the output screen and I’ll just display a hollow message of further away your name suppose if your name is say ABC I will say hello ABC on the sphere but how do i use it get us and put us in reality with this let us try and identify the program for this so as usual the program always begins with the header file harsh include stdio.h now get us food as functions are a part of your h0 h itself so let’s start with the main task i’ll say void main now as usual again discuss the input the process and the output values what you are going to read as input you are going to read a string as input a set of characters input to store the set of characters what we need to you should I use a character variable or sugar is a character array character variable will swing only one character whereas character array stores a set of characters yes so in this case in the input side are using a character I what are the contents which are there in the input character array the same are supposed to be even displayed on the output side but with a message say hello let’s see hub I proceed with this particular task some supposed to define a character array not necessarily the character he has to be defined as care CH itself let me try a different character array name as care n of 20 now here n of 20 square Rockets have been read us off which means that this n can store a maximum set of how many characters 19 characters even though the size hasn’t specified extent is some of you might have guessed as 20 before I spoke the pedigree number basically the size has been set as 20 but it will read maximum on 19 characters because one character has to be preserved for null character that is to intermission character hence what we do is we read only 19 characters for the suicide right ok you can have input less than 19 carrots or so but the maximum space is 19 characters let us proceed and ask the user to enter the name so I’ll display a message printf enter your name I’ll redo this particular name so I’ll read the name using the function which we are stirring that is get S the near the character the near the character in this case is n so I say get s n so use the function get us to read the name and store into the record as n if input goes as ABC so in this case n will store a b c and then yes you got it right that is / 0 null character now suppose this display this particular name with a welcome message I can say welcome so and so or hollow so and so what are the name which you have entered we are we are still conversant with the printer construction to display the message you can use a different section rather using printf i can use put s to display messages as i put s double quotes here i will say hallo which means that this message will display as it is on the screen you might wonder that i have been using printf to do this task you can even use a putas as alternate for this basically the advantage of using put s is that after displaying the name or displaying the message the cursor will automatically roll down the next line when I say to printf in this instruction after saying enter your name up saying enter your name the cursor was left on the same line you could have entered the name next to this particular message on the screen but in this case when I say put this hello it displays a message called as hollow on the screen and then rolls down the cursor to the next line so after hello if you want to display the name next to a low then you can’t use put as you would use printf so here are using put as hollow so that the cursor will roll down to the next line and after that I will use the actual purpose of footage so here I’ll say put s bracket I’ll say n what this function does this function will display the content of n as it is on the screen followed by a preceded by a message called as hollow it will display all the characters of n as it is till it finds a null character assume that we have entered a name called a shape Aditya I’ll ask you to enter your name assume that the name is Aditya so the standard output goes something in the sort so if I say enter your name now as printf believe the curse on the same line so you can enter the input at this place let me try the input as say ad I p why a so now this entire string when I pipe the string and hit the enter key this ring goes into n so first location is filled with a second location with the d i T by a and so on and then up and sitting with null character on the output see how the output appears so put as hollow will display a message as hollow will it leave the castle same line no the curse will all turn around on the next line and then the contents of n will displayed n is odd it there so here I’ll say a d I t.y a will it not display all the 20 characters no because after this it finds a null character so here are used to test to display the contents of array and get us is used to read the contents from the user and store into an array so that is about the concepts of Gators and fo test functions thank you

1 thought on “Multiple Character Input Output Function – Data Input and Output – C Programming Language

  1. Hello Friends,
    Watch Complete Video Series of Subject Structured Programming Approach in C Programming only on Ekeeda Application.
    Use Coupon Code "FIRSTTIME" and access any one Subject for Complete one month free.
    Download Ekeeda Application and take advantage of this offer.

Leave a Reply

Your email address will not be published. Required fields are marked *