Advertisement
tobast

Untitled

Oct 25th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAX_STRING_SIZE 201 // Inclut le '\0'
  5.  
  6. char string[MAX_STRING_SIZE];
  7. int stringSize;
  8.  
  9. char toUpper(char ch)
  10. {
  11.     if(ch >= 'a' && ch <= 'z')
  12.         return ch - ('a'-'A');
  13.     return -1;
  14. }
  15.  
  16. void printInitiales()
  17. {
  18.     int pos;
  19.  
  20.     if(string[0] != ' ')
  21.         printf("%c", toUpper(string[0]));
  22.    
  23.     for(pos=0; pos < stringSize-1; pos++) // On garde un caractère de réserve à la fin, car on utilise string[pos+1]
  24.     {
  25.         if(string[pos] == ' ' && string[pos+1] != ' ') // Le caractère suivant est une lettre
  26.         {
  27.             printf("%c", toUpper(string[pos+1]));
  28.             pos++; // Le caractère suivant le peut pas être lui aussi une initiale
  29.         }
  30.     }
  31.     printf("\n");
  32. }
  33.  
  34. int main(void)
  35. {
  36.     scanf("%d", &stringSize);
  37.     int pos;
  38.  
  39.     char drop; // variable "poubelle" pour virer le \n
  40.     scanf("%c", &drop);
  41.  
  42.     for(pos=0; pos<stringSize; pos++)
  43.         scanf("%c", &(string[pos]));
  44.  
  45.     printInitiales();
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement