Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Use osprey for todays practice problems to practice for exam #3
- Problem #1:
- This problem is about declaring strings and printing them out. Program the following:
- 1) Declare a STRING and initialize it to the value “2019”.
- 2) Declare a CHARACTER POINTER and initialize it to NULL.
- 3) Declare another CHARACTER POINTER and initialize it to the value “2021”.
- 4) Compose 3 printf() statements to print the 3 strings you just declared.
- > Also print the length of those strings using strlen().
- You WILL get a segmentation fault error from this program. Why does that occur?
- Problem #2:
- This problem is about initializing strings and printing them in reverse. Program the following:
- 1) Declare a string and initialize it to a short sentence.
- > For example: "Godzilla is gonna win."
- 2) Use a for loop to print the string to screen one character at a time backwards.
- > Your for loop should determine when to stop by using the strlen() function.
- Now modify the program and declare and initialize the array
- using pointer notation like in problem 1. Did it work the same?
- SAMPLE OUTPUT:
- .niw annog si allizdoG
- Problem #2B:
- Modify the previous problem to print the array to screen using the %s modifier with
- printf(). What is the difference printing it using the loop or printing with %s?
- Problem #3:
- This problem involves taking strings as input. Program the following:
- 1) Declare a string of size 80 and initialize it to nothing.
- > For example: [insert string] = "";
- 2) Prompt the user to enter in a sentence. It must be less than 80 characters in length.
- 3) Scan the sentence into the string. USE fgets().
- 4) Print the string to the screen to make sure it scanned correctly.
- SAMPLE OUTPUT:
- Enter in a sentence up to 80 characters: Hot take, Raisin Bran isn't bad.
- Here is your sentence: Hot take, Raisin Bran isn't bad.
- Problem #4:
- This program mixes loops, if/else, arrays, and strings together.
- Using the program from problem 3, add code that will check whether each
- letter in the sentence is upper-case or lower-case. Program the following:
- 1) Import the library with character functions to check for upper and lower case.
- > Remember the kahoot?
- 2) After scanning the string from the user, write a for loop that will iterate through the entire string.
- 3) Using if/else, check if the letter is upper or lower case, and print it to the screen.
- > Remember that spaces exist in the string, try to manage those.
- SAMPLE OUTPUT:
- Enter in a sentence up to 80 characters: Can I get that pizza BONELESS?
- C is Uppercase
- a is Lowercase
- n is Lowercase
- I is Uppercase
- g is Lowercase
- e is Lowercase
- t is Lowercase
- t is Lowercase
- h is Lowercase
- a is Lowercase
- t is Lowercase
- p is Lowercase
- i is Lowercase
- z is Lowercase
- z is Lowercase
- a is Lowercase
- B is Uppercase
- O is Uppercase
- N is Uppercase
- E is Uppercase
- L is Uppercase
- E is Uppercase
- S is Uppercase
- S is Uppercase
- Problem 4B ## CHALLENGE ##
- Modify problem 4 to check whether the letters are vowels or consonants rather than upper-case/lower-case.
- (This one is a bit tricky, you may need to make some functions for it).
- SAMPLE OUTPUT:
- Enter a sentence up to 80 characters in length:
- Can I get that pizza BONELESS?
- C is consonent
- a is vowel
- n is consonent
- I is vowel
- g is consonent
- e is vowel
- t is consonent
- t is consonent
- h is consonent
- a is vowel
- t is consonent
- p is consonent
- i is vowel
- z is consonent
- z is consonent
- a is vowel
- B is consonent
- O is vowel
- N is consonent
- E is vowel
- L is consonent
- E is vowel
- S is consonent
- S is consonent
Add Comment
Please, Sign In to add comment