Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7.     // ask the user for the name
  8.     string name = GetString();
  9.     string initials = "";
  10.    
  11.    
  12.     // now get the initials
  13.    
  14.    
  15.        
  16.         // run through the string and put the first character into the initials string. ascii 32 = space button
  17.        
  18.         if(name != NULL)
  19.         {
  20.        
  21.             for(int i = 0, n = strlen(name); i < n; i++)
  22.             {
  23.                
  24.                 if(i == 0)
  25.                 {
  26.                     initials = initials + name[i];
  27.                 }
  28.                
  29.                 else if(name[i] == 32)
  30.                 {
  31.                     initials = initials + name[i+1];
  32.                 }
  33.                
  34.             }
  35.         }
  36.        
  37.    
  38.    
  39.    
  40.     // Print out the initials
  41.     printf("Your initials are: %s\n", initials);
  42.    
  43.    
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement