Practice Problems

Strings

Notice when you get compile errors (when gcc gives you an error)
vs. errors that crash the program (run-time errors)
vs. logical errors (compile and run fine but problem with your code)

  1. How do the loops differ for copying an array vs. a character array? For example, write a function that copies an int array to another int array and write a function that does it for a string (character) array. (Note the different loop structure that should be used, what the condition is to know when to stop looping, other things that need to be done)
  2. Write a function that takes a string as a parameter and returns the number of alpha-numeric characters in the string.
  3. Write a function that takes a string as a parameter and returns the number of vowels in the string.
  4. Write a function that takes a string as a parameter and REMOVES all spaces in the string (returns nothing, function should modify the original string passed to the function).
  5. Write a function that takes a string as a parameter and returns the number of sentences. Assume a sentence ends in either a period, ! or ?
  6. Write a function that takes a string as a parameter and returns the number of words in the string.
  7. What is the result of
     strcmp( "april", "April" )
    	
  8. How do you convert a character to upper case? (What is the function you need to call, and what other header file do you need to import)
  9. Show three different ways to initialize the variable name with "Cookie".
  10. What's the difference between strcat and strcpy ?
  11. If you know the string variable filename ends with .txt how can you remove the extension from the string?
  12. Using fgets, read in a character and 3 integers and store them in to appropriate variables.
  13. Write the code to print out the size of the string in a variable named title.
  14. What happens if your string does not contain a null character in the array?
  15. Convert the string variable score to an integer value using the function atoi
  16. What is the function to call to determine whether a character is a digit or not?