![]() ![]() strcat - Appends one string at the end of another.strupr - Converts a string to uppercase.strlwr - Converts a string to lowercase.With every C compiler a large set of useful string handling library functions are provided in string.h file. Though workable this is the best of the ways to call a function, you would agree. ![]() If we are prepared to take the trouble we can make scanf() accept multi-word strings by writing it in this manner: char name Though gets() is capable of receiving only one string at a time, the plus point with gets() is that it can receive a multi-word string. Also, on displaying a string, unlike printf(), puts() places the cursor on the next line. The program and the output are self-explanatory except for the fact that, puts() can display only one string at a time (hence the use of two puts() in the program above). The way to get around this limitation is by using the function gets().The usage of functions gets() and its counter part puts() is shown below.Īnd here is the output. Therefore names such as "Vineet Choudhary" would be unacceptable. scanf() is not capable of receiving multi-word strings.This is because the C compiler doesn’t perform bounds checking on character arrays. The length of the string should not exceed the dimension of the character array.While entering the string using scanf() we must be cautious about Also we will not use a & sign for receiving string values. name='B' Īs we saw in above example placeholder for string variables is %s. (It's only one character and its value is 0, however we show it with two characters to remember it is a character type, not an integer).Įqually we can make that string by assigning character values to each member. We call this character as NULL character and show it with \0 character. C determines end of a string by a zero value character. If user enters "Vineet" then the first member of array will contain 'V', second cell will contain 'i' and so on. Printf("Hello, %s, how are you ?\n",name) Each member of array contains one of characters in the string. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |