daniel_lawson9999

Daniel Lawson Initials Program

Sep 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. //Daniel Lawson 9/20/17
  6. //additionally include string.h for getting the length of a string with strlen(), and include cytype.h to convert a character to uppercase with toupper()
  7.  
  8. int main(void){
  9.     string name = get_string();//get the name
  10.     char charPrevious = ' ';//keep track of previous character
  11.  
  12.     for(int i = 0; i < strlen(name);i++){//look at each character in the string
  13.         if(charPrevious == ' '){
  14.            printf("%c", toupper(name[i]));//if the previous  character was a space, print the initial
  15.         }
  16.         charPrevious = name[i];//set the previous initial to equal the current one
  17.     }
  18.     printf("\n");//print \n because cs50
  19. }
  20.  
  21. /*provided output goal
  22. Zamyla Chan
  23. ZC
  24. ~/workspace/pset2 $ ./initials
  25. robert thomas bowden
  26. RTB
  27. */
Advertisement
Add Comment
Please, Sign In to add comment