L11 Strings
L11 Strings
Module-11: String in C
Content for the slides have been taken from the various sources and
from the reference books.
In the program,
Output
Enter a line of string:
C++ 20 is the latest
version of C++ yet.
Vowels: 9
Consonants: 16
Digits: 2 White
spaces: 8
Some Examples
• Creation of srtlen() Function
Some Examples
Creation of
srtcmp()
Function
sprintf() function
int sprintf (char *str, const char *controlstring [, argument!, argument2, ,.........] );
•This function is same as printf ( ) function except that instead of sending the
formatted output to screen, it stores the formatted output to the string.
•With the help of this function, we can convert variables of any data type to string.
•A null character is appended at the end automatically.
•This function returns the number of characters output to the string excluding the
null character.
•It is the responsibility of the programmer to take the size of string large enough to
store all the arguments, so that no overflow occurs.
sprintf() function
sprintf() function
sscanf() function
int sscanf (const char *str, const char *controlstring [, address 1, address2, …];
•This function is same as the scanf () function except that data is read from a string
rather than the standard input.
•We can read the formatted text from a string and convert it into variables of
different data types.
sscanf() function
Thank you for your attention!
< Questions?