Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. int main(int argc, string argv[])
  7. {
  8. //ask user for input
  9. string s = get_string();
  10.  
  11. //make sure get_string return a string
  12. if(s!=NULL)
  13. {
  14. //if first letter is a char, print it
  15. if(s[0] != ' '){
  16.  
  17. //check to see if char is lowercase
  18. if(islower(s[0])){
  19.  
  20. //print first letter, to uppercase
  21. printf("%c", toupper(s[0]));
  22.  
  23. } else{
  24.  
  25. //print first letter as it is
  26. printf("%c", s[0]);
  27.  
  28. }
  29. }
  30.  
  31. for(int i=0, n=strlen(s); i<n; i++){
  32.  
  33. //iterate forward to get the index where char after space is at
  34. if(s[i-1] == ' ' && s[i] != ' '){
  35.  
  36. //check to see if char is lowercase
  37. if(islower(s[i])){
  38.  
  39. //print first letter, to uppercase
  40. printf("%c", toupper(s[i]));
  41.  
  42. } else{
  43.  
  44. //print first letter as it is
  45. printf("%c", s[i]);
  46.  
  47. }
  48. }
  49. }
  50.  
  51. printf("\n");
  52. return 0;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement