Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <ctype.h>
- //Daniel Lawson 9/20/17
- //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()
- int main(void){
- string name = get_string();//get the name
- char charPrevious = ' ';//keep track of previous character
- for(int i = 0; i < strlen(name);i++){//look at each character in the string
- if(charPrevious == ' '){
- printf("%c", toupper(name[i]));//if the previous character was a space, print the initial
- }
- charPrevious = name[i];//set the previous initial to equal the current one
- }
- printf("\n");//print \n because cs50
- }
- /*provided output goal
- Zamyla Chan
- ZC
- ~/workspace/pset2 $ ./initials
- robert thomas bowden
- RTB
- */
Advertisement
Add Comment
Please, Sign In to add comment