Advertisement
ssoni

initials.c

Jan 21st, 2022
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. int main(void)
  7. {
  8.     string name;
  9.     name = get_string("");
  10.  
  11.     //check first letter only
  12.     //convert to uppercase as well
  13.     if (isalpha(name[0]) != 0)
  14.     {
  15.         printf("%c", toupper(name[0]));
  16.     }
  17.  
  18.     //find letters after a space
  19.     //If I have a space,
  20.     //then check if next char is a letter
  21.     //If it is, print uppercase version of next letter
  22.     for (int i=0; i<strlen(name); i++)
  23.     {
  24.         if (name[i] == ' ')
  25.         {
  26.             if (isalpha(name[i+1]) != 0)
  27.             {
  28.                 printf("%c", toupper(name[i+1]));
  29.             }
  30.         }
  31.     }
  32.     printf("\n");
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement