CH 10. Strings
CH 10. Strings
Strings
- In input and output examples, after ↦ symbol is to explain the input and output.
[ Problem 1 ] Read a string (without spaces) and print lower-case letters only.
HelloWorld elloorld
AbCdEEff bdff
[ Problem 2 ] Read an integer, convert each digit into a character, store the characters as a string
in reverse order and print them.
9756 6579
12345 54321
-1-
<Advanced C Programming and Lab> Ch 10. Strings
[ Problem 3 ] Read 2 strings (including spaces) and check whether the two strings match to each
other.
- Do not use library functions strlen( ) and strcmp( )
- Print the length of the first string and print 1 if two are matched, otherwise 0.
Hello 5 0
world
programming 11 1
programming
- Print the length of the first string and print 1 if str1 includes str2, otherwise 0
Hello 5 0
world
Helloworld 10 1
low
-2-
<Advanced C Programming and Lab> Ch 10. Strings
[ Problem 5 ] Read an integer N. Read N strings (without spaces). Print the shortest length string
(without spaces). The maximum length of a string is 100.
[ Problem 6 ] Read two strings str1 and str2 (without spaces) and one integer p. Insert str2 into
str1 at the position designated by the integer p.
Hint: If p#0, create a new string and use strncpy() function and strcat() function in <string.h>
library.
123 ↦ str2
2 ↦ where to insert
abc ↦ str2
4 ↦ where to insert
[ Problem 7 ] Extending Problem 6. Read one more integer to indicate whether reverse the string
or not.
- Following the rules of problem 6
-3-
<Advanced C Programming and Lab> Ch 10. Strings
[ Problem 8 ] Read two strings (without spaces) using scanf( ) and concatenate two strings and
print them. Compare two strings using the lexicographic order, put the bigger string first.
sejong universitysejong
university
[ Problem 9 ] Read a string (without spaces) and check whether it is palindrome or not.
- Define and use a function check()
- main()
◦ Read a string
aibohpphobia 12 1
[ Problem 10 ] Read 5 strings without spaces (lowercase characters only) and sorts them in
lexicographical order.
belloo apricot
apricot bello
hello hello
sejong myname
myname sejong
-5-