How to convert a normal integer to its bibliographic format in c?

3

I want to know how to convert, for example, the following string:

"Barack Obama" for "OBAMA, Barack".

That is, pro bibliographic format, type when citing authors of books / articles. But I want to know how to convert any name size to this format, it can be with 2 names (as in the example above) or with 3, 4, 5 ... n names, for example:

Lionel Andrés Blablabla Soccer Player Messi This name would look like this: MESSI, Lionel Andrés Blablabla Soccer Player.

I know how to convert if I know how many names the person's full name will have, but I want to know how to do this for any integer size, ie, not needing to know how many names the person has in the whole name. p>

Here is the code I've been able to do so far (it only works for whole names that have 6 names in total):

char nome[30][100];
int i, j;

for(i = 0; i < 6; i++)
    scanf("%s", nome[i]);
for(j = 5; j > 4; j--)
    printf("%s,", strupr(nome[j]));
for(i = 0; i <= 4; i++)
    printf("%s ", nome[i]);
    
asked by anonymous 19.10.2016 / 05:09

1 answer

2
char* nome="Leonel da Silva Messi";

char* aux=strdup(nome);                // aux = cópia do nome
char* ue=strrchr (aux,' ');            // apontador para o ultimo espaço
*ue='
char* nome="Leonel da Silva Messi";

char* aux=strdup(nome);                // aux = cópia do nome
char* ue=strrchr (aux,' ');            // apontador para o ultimo espaço
*ue='%pre%';                              // aux = "Leonel da Silva%pre%Messi"
printf("%s, %s\n", ue+1, aux);         // ... ou strupr(ue+1) se estveres em MS
'; // aux = "Leonel da Silva%pre%Messi" printf("%s, %s\n", ue+1, aux); // ... ou strupr(ue+1) se estveres em MS
    
19.10.2016 / 11:23