Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <string.h>
- #include <stdio.h>
- int main(void)
- {
- // ask the user for the name
- string name = GetString();
- string initials = "";
- // now get the initials
- // run through the string and put the first character into the initials string. ascii 32 = space button
- if(name != NULL)
- {
- for(int i = 0, n = strlen(name); i < n; i++)
- {
- if(i == 0)
- {
- initials = initials + name[i];
- }
- else if(name[i] == 32)
- {
- initials = initials + name[i+1];
- }
- }
- }
- // Print out the initials
- printf("Your initials are: %s\n", initials);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement