daily pastebin goal
47%
SHARE
TWEET

initial

a guest Jun 13th, 2018 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int main()
  2. {
  3.     int len = 0; //length set to 0
  4.     int i = 0; //length count to 0
  5.     char name[31]; //set array of name to 31 inc null pointer
  6.  
  7.     printf("Please enter your name:\n");
  8.  
  9.     while (!isalpha(name[0])) //isAlpha checks against the unicode alphabet. When alphabet is not found, a print message is displayed
  10.     {
  11.         printf("This is not valid input. Please reenter. \n");
  12.         fgets(name, 30, stdin); //input max 30 char and put into name. FGETS gets the array, the size going to be entered into it
  13.     }                       //and then the stream from where the characters are read from
  14.  
  15.     len = strlen(name); //strlen takes note of length of characters. Here, strlen is applied to name and then assigned to len for later use
  16.  
  17.  
  18.     printf("These are your initials.\n");
  19.  
  20.     for (i = 0; i < len; i++)
  21.     {
  22.  
  23.         if (i == 0)
  24.         {
  25.             putchar(toupper(name[i]));
  26.         }
  27.  
  28.         else if (name[i] == ' ')
  29.         {
  30.             putchar(toupper(name[i + 1]));
  31.  
  32.         }
  33.  
  34.     }
  35.  
  36.     getchar();
  37.     getchar();
  38.  
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top