M4ritimeSeeker

PASS Week 11: Strings

Apr 4th, 2022 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. KAHOOT ANSWERS LINK:
  2.  
  3. https://pastebin.com/3MVhyWxV
  4.  
  5.  
  6.  
  7.  
  8. WARMUP (Review from Last Week): Array Reversal
  9.  
  10. Write a program that creates an array of 5 integer values {1, 2, 3, 4, 5}, and "reverses" it.
  11. You will copy the first array's values into an empty second array, but backwards. Effectively making
  12. the second array a "reverse" of the first.
  13.  
  14. You will have about 4 loops total. One loop to fill the first array (Array A) with values,
  15. a second loop to print Array A, a third loop to fill the second array (Array B) with A's values backwards,
  16. and a fourth loop to print Array B.
  17.  
  18. SAMPLE OUTPUT
  19.  
  20. A: 1 2 3 4 5
  21. B: 5 4 3 2 1
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. PROBLEM #1: Taking Multiple Strings and Data as Input
  39.  
  40. Create a program that will prompt the user to enter string values for their first name, last name, and age.
  41. However, you must take all 3 inputs IN A SINGLE scanf statement. Then print them back out to the user.
  42. First name will be stored in a string, last name will be stored in a second string, and age is a normal integer.
  43.  
  44. SAMPLE OUTPUT:
  45.  
  46. Enter in your first name, last name, and age:
  47. Justin Bentley 21
  48. Hello Justin Bentley age 21
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. PROBLEM #2: Using fgets(), Strings and String Functions
  62.  
  63. Compose a program that prompts the user to enter 3 separate sentences
  64. as input and store them in 3 separate strings (Each array will be 40 in length).
  65. Then copy/concatenate all 3 sentences into one huge string of length 120.
  66.  
  67. Prompt the user and use fgets() to read the input into the first array.
  68. Then prompt the user for a second sentence and store it in the second array.
  69. Then do the same again storing a third string into a third array.
  70.  
  71. Next, use the strcpy() function to copy the first array into the fourth array.
  72. Then use the strcat() function to concatenate the second array to the end of the fourth array.
  73. Then do it again, concatenating the third array into the fourth array.
  74. Then print the fourth array using the %s modifier, and the length using strlen().
  75.  
  76. SAMPLE OUTPUT:
  77.  
  78. Enter in your first name: Justin
  79. Enter in your middle name: William
  80. Enter in your last name: Bentley
  81.  
  82. JustinWilliamBentley
  83.  
  84. Length is 23
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. PROBLEM #3: String Reversals
  101.  
  102. Create a program that will reverse a string
  103. Declare and initialize a string with the value: "This is a sentence"
  104. Then use a loop and the strlen() function and print the string one character at a time backwards.
  105.  
  106. SAMPLE OUTPUT:
  107. ecnetnes a si sihT
  108.  
  109.  
  110. SAMPLE OUTPUT (With the input https://www.youtube.com/watch?v=dQw4w9WgXcQ):
  111.  
  112. QcXgW9w4wQd=v?hctaw/moc.ebutuoy.www//:sptth
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. PROBLEM #4: Converting Strings to Uppercase
  127.  
  128. Compose a program with a character array of 81 characters in size. Also declare
  129. an integer variable to store the size of a sentence later on.
  130.  
  131. Prompt the user to enter in a sentence up to 80 characters and then store it in the array using fgets().
  132. Get the sizeof() the sentence, and store it in the integer you made earlier.
  133. Now, using a for loop, go through the sentence one character at a time check if they are uppercase using the isupper() function.
  134. If it ISN'T uppercase, then make it uppercase using the toupper() function.
  135. Finally, print out the new string using printf.
  136.  
  137. Also, remove the carriage return ā€˜\n’ character from the array if you used fgets() to get the input string.
  138.  
  139.  
  140. SAMPLE OUTPUT:
  141.  
  142. Enter in a sentence: This is a sentence
  143. THIS IS A SENTENCE
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. PROBLEM #5: Counting Specific Characters in a String
  158.  
  159. Re-using your solution to problem #4, modify the program to read in a sentence up to 80
  160. characters but this time count the number characters THAT ARE NOT spaces, periods,
  161. exclamation points or commas.
  162.  
  163. Print out the total and this should be the number of characters that weren't specified.
  164.  
  165. SAMPLE OUTPUT:
  166.  
  167. Enter in a sentence: This, is a sentence!
  168. There are 15 characters.
  169.  
  170.  
  171.  
Add Comment
Please, Sign In to add comment