Guest User

Untitled

a guest
Jul 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. p. 320 Exercise 12. Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program should output the two strings it created. For example, if the input to the program is "2BeOrNotToBe", the output of the program should be
  2.  
  3. 2BeOrN
  4. otToBe
  5.  
  6. If the input to the program is "ToBeOrNotToBe", the output of the program should be
  7.  
  8. ToBeOrN
  9. otToBe
  10.  
  11.  
  12. /* Daniel Wilkins - Lab 5 Part 2 */
  13.  
  14. /* Set up the includes */
  15. #include <stdio.h>
  16.  
  17. int countchar (char []);
  18. int main()
  19.  
  20. {
  21. char message [] = "";
  22. int numchar;
  23.  
  24. printf("\nEnter a phrase: ");
  25. gets(message);
  26. numchar = countchar (message);
  27. printf ("Character number: %d\n", numchar);
  28. return 0;
  29.  
  30. }
  31.  
  32. int countchar (char list[])
  33. {
  34. int i, count = 0;
  35.  
  36. for (i = 0; list[i] != '\0'; i++)
  37. count++;
  38.  
  39. return (count);
  40. }
Add Comment
Please, Sign In to add comment