Advertisement
takai

Abrevia Nome

Oct 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. /*
  2. 5 Abreviação de nome
  3. Escreva um programa para ler um nome completo do teclado terminado com um ponto. Seu programa
  4. deve então imprimir o mesmo na forma abreviada. Exemplo: o nome Pedro Olmo Stancioli
  5. Vaz de Melo. deve ser abreviado para P.O.S.V.M.. Note que o processo de abreviação deve ignorar
  6. palavras que começam com caracteres minúsculos. Considere que o usuário irá inserir apenas nomes
  7. válidos terminados com o caractere . e sem acentos.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. void main() {
  15.  
  16.     char name[150];
  17.     int i=0, j=0;
  18.  
  19.     printf ("Digite o nome:\n");
  20.  
  21.     fgets (name, 150, stdin);
  22.  
  23.     for (i=0; name[i]!='\n'; i++){
  24.  
  25.         if (name[i] == ' ')
  26.         j++;
  27.  
  28.     i=0;
  29.  
  30.     while(name[i]!= ' ') {
  31.  
  32.         printf("%c",name[i]);
  33.         i++;
  34.  
  35.     }
  36.  
  37.     while(j>1) {
  38.  
  39.         if((name[i+1]=='d') && (name[i+2]=='a' ||name[i+2]=='o'||name[i+2]=='e')) {
  40.  
  41.             if(name[i+3]==' ') {
  42.  
  43.                 printf(" %c%c",name[i+1],name[i+2]);
  44.  
  45.                 i+=3;
  46.  
  47.                 j--;
  48.  
  49.             }
  50.  
  51.             else if(name[i+3]=='s'&&name[i+4]==' ') {
  52.  
  53.             printf("%c%c%c",name[i+1],name[i+2],name[i+3]);
  54.             i+=4;
  55.             j--;
  56.  
  57.             }
  58.  
  59.         }
  60.  
  61.         else {
  62.  
  63.             i++;
  64.  
  65.             printf(" %c.",name[i]);
  66.  
  67.             j--;
  68.  
  69.         }
  70.  
  71.         while(name[i]!=' '){
  72.  
  73.             i++;
  74.  
  75.        }
  76.  
  77.        i++;
  78.  
  79.        printf(" ");
  80.  
  81.        while(name[i]!='\n')   {
  82.  
  83.             printf("%c",name[i]);
  84.  
  85.             i++;
  86.  
  87.         }
  88.  
  89.     }
  90.  
  91. }
  92.  
  93.     system ("PAUSE");
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement