Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_STRING_SIZE 201 // Inclut le '\0'
- char string[MAX_STRING_SIZE];
- int stringSize;
- char toUpper(char ch)
- {
- if(ch >= 'a' && ch <= 'z')
- return ch - ('a'-'A');
- return -1;
- }
- void printInitiales()
- {
- int pos;
- if(string[0] != ' ')
- printf("%c", toUpper(string[0]));
- for(pos=0; pos < stringSize-1; pos++) // On garde un caractère de réserve à la fin, car on utilise string[pos+1]
- {
- if(string[pos] == ' ' && string[pos+1] != ' ') // Le caractère suivant est une lettre
- {
- printf("%c", toUpper(string[pos+1]));
- pos++; // Le caractère suivant le peut pas être lui aussi une initiale
- }
- }
- printf("\n");
- }
- int main(void)
- {
- scanf("%d", &stringSize);
- int pos;
- char drop; // variable "poubelle" pour virer le \n
- scanf("%c", &drop);
- for(pos=0; pos<stringSize; pos++)
- scanf("%c", &(string[pos]));
- printInitiales();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement