DragonOsman

Initials

Oct 13th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. // Osman Zakir
  2. // 10 / 13 / 2016
  3. // Introduction to Computer Science
  4. // Problem Set 2, initials.c
  5. // Program to ask the user for their name and output just their initials, followed by a newline.
  6.  
  7. #include <cs50.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11.  
  12. int main(void)
  13. {
  14.     printf("Please enter your full name: ");
  15.     string name = GetString();
  16.     string split_string = strtok(name, " ");
  17.     char initials[3];
  18.    
  19.     while (split_string != NULL)
  20.     {
  21.         for (int i = 0, n = strlen(split_string); i < n; i++)
  22.         {
  23.             if (strncmp(split_string, " ", split_string[i]))
  24.             {
  25.                 initials[i] = toupper(split_string[i + 1]);
  26.             }
  27.             printf("%c", split_string[i]);
  28.         }
  29.         printf("\n");
  30.         split_string = strtok(NULL, " ");
  31.     }
  32. }
Add Comment
Please, Sign In to add comment