2
For one or two names repeated, it works well, but if I make them all the same he repeats them ten times. I’ve tried using flag, but I can’t understand the reasoning.
#include <stdio.h>
#include <stdlib.h>
/*
Lucas Correia, 2018
*/
int main(int argc, char *argv[]) {
char nomes[5][50];
int i=0, j=0, flag = 0;
for(i=0; i < 5; i++){
printf("Informe o nome:");
scanf(" %[^\n]s", nomes[i]);
}
for(i=0; i < 5; i++){
for(j = i+ 1; j < 5; j++){
if(stricmp(nomes[i], nomes[j])==0){
printf("\nRepetead: %s", nomes[i]);
flag = 1;
if(!flag){
break;
}
}
}
}
return 0;
}
You can create another variable that stores repeated names, then just enter there if it doesn’t exist, then just print
– Fábio Morais
Set "repeated". If there are two equal ones in the whole list is already repeated? Or only when it appears for the second time is repeated?
– Maniero
If there are two equal ones in the list it is already repeated. I am trying to understand correctly comparison of strings to use in a name validation. For example, if there is already a name in the list, it asks the user to type the name again.
– Lucas Correia
@Lucascorrhea Can use my implementation, only instead of using
nomes_repetidos
asks again for a different name– Fábio Morais