Created
October 3, 2019 04:25
-
-
Save TopRoupi/880ddb4d7f0e4d13e9fe4bf14e8f9ef9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void corta(char txt[],int ini,int fim){ | |
ini -= 1; | |
int i; | |
for (i = 0; txt[fim+i] != '\0'; i++) | |
txt[ini+i] = txt[fim+i]; | |
txt[ini+i] = '\0'; | |
} | |
int maiuscula(char letra){ | |
if (letra <= 90 && letra >= 65) | |
return 1; | |
return 0; | |
} | |
int qtd_maiusculas(char texto[]){ | |
int contador = 0; | |
for(int i = 0; texto[i] != '\0'; i++){ | |
if(maiuscula(texto[i])) | |
contador++; | |
} | |
return contador; | |
} | |
int qtd_abreviacoes(char texto[]){ | |
int contador = 0; | |
for(int i = 0; texto[i] != '\0'; i++){ | |
if(maiuscula(texto[i]) && texto[i+1] == '.') | |
contador++; | |
} | |
return contador; | |
} | |
void abrevia(char nome[]){ | |
if((qtd_maiusculas(nome) - qtd_abreviacoes(nome)) == 2) | |
return; | |
else{ | |
int ignorar = qtd_abreviacoes(nome) + 1; | |
int i = 0; | |
do{ | |
if(maiuscula(nome[i])){ | |
if(ignorar == 0){ | |
nome[i+1] = '.'; | |
int j; | |
for(j = 0; nome[i+2+j] != ' '; j++); | |
corta(nome, i+3, i+2+j); | |
abrevia(nome); | |
break; | |
} | |
ignorar -= 1; | |
} | |
i += 1; | |
} while (1); | |
} | |
} | |
int main(void){ | |
char txt[40] = "Breno Nunes awd Agua Galvao"; | |
// corta(txt, 8, 11); | |
// puts(txt); | |
// printf("%d\n", qtd_maiusculas(txt)); | |
// printf("%d\n", qtd_abreviacoes(txt)); | |
abrevia(txt); | |
puts(txt); | |
return 0; | |
} | |
//B r e n o N u n e s G a l v a o \0 | |
//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment