-5
struct registro{ /*Estrutura para guardar os dados do usuário*/
char usuario[50]; }atual[1000], *ptr;
main() {
int v = 0; verific = 0; //posicao e variavel para comp. de string
volta_usuario:
printf("\n\t\t\tUsuário: ");
gets(atual[v].usuario);
verific = verifica_usuario(&v);
if(verific == 0) {
printf("\t\t\tUsuário já existente");
goto volta_usuario;
} v++; goto volta_usuario;} int verifica_usuario(int *ptr){
int i;
int cmp1;
int cmp2;
for(i = -1; i < *ptr; i++) {
cmp1 = tolower(atual[*ptr].usuario);
cmp2 = tolower(atual[i + 1].usuario);
if(strcmp(cmp1,cmp2) == 0){
return 0;
}
}
return 1;}
The above code should ask the user for a name, when calling the function verifica_usuario(&v);
the program should convert the last string
read to lowercase, duration a loop, convert the other strings (also to lowercase) and then compare and see if there are identical strings. My goal is: if the person type "name" and then type "NAME" or "Name" (etc.) the program must recognize that this user already exists, that is, it does not differentiate between upper and lower case. I have tried several ways to fix the bug of this highlighted function, but without success. I would like help to solve this problem.
To
stricmp
of maniero’s response solves your comparison problem by keeping the state of the string for later presentation– Jefferson Quesado
Taking advantage,
goto
? You are making a loop the wrong way. Try to make a flow chart of the data and then implement the proper loop. See more in this question on the subject: https://answall.com/q/251860/64969– Jefferson Quesado
@Jeffersonquesado, could guide me on how to perform this code in the right way, helping me how to do it, at least the function?
– eddunic
You understood Maniero’s answer?
– Jefferson Quesado
I don’t get it, no.
– eddunic
Then why did you mark his answer as correct?
– Jefferson Quesado
I’m new here.
– eddunic
Do the [tour], will be of great benefit
– Jefferson Quesado
A, thanks for the tip.
– eddunic
If you do not understand a reply, please seek clarification from the author. If you don’t, the person who responded is convinced that you were able to help when you didn’t. This also avoids creating "repeated" questions by not realizing the answers
– Isac