0
I am assigning the return of the function checks code to a flag. The idea is to make the flag trigger the loop if the code is incorrect
char *leValidaCodigoAviao(char *msg, char *msgErro){
char *pNome=0, nome[MAX];
strcpy(nome, "");
int stringTam=0, flag=1, verificador=0;
do{
printf("%s", msg);
fflush(stdin);
scanf("%[^\n]s", nome);
if(strlen(nome)==0){
printf("%s", msgErro);
flag=0;
}else if(strlen(nome)<COD_ID || strlen(nome)>COD_ID){
flag=0;
}else{
verificador = verificaCodigo(nome);
printf("%d", verificador);
flag = verificador;
}
}while(!flag);
system("cls");
getch();
return pNome = nome;
}
int verificaCodigo(char nome[]){
int i, flag=1;
for(i=0;i<COD_ID;i++){
if(i<3){
if(!isalpha(nome[i])){
flag=1;
break;
}
}else{
if(!isdigit(nome[i])){
flag=1;
break;
}
}
}
return flag;
}
It was only supposed to enter the loop if the code was incorrect. For example, ma10340 -> 3143mdafd -> mar103b. Otherwise, it exits the loop. I already changed the values of the flags, but nothing changed.
– Lucas Correia
But you must return
0
if you’re wrong and1
if you’re right, assuming that right is 3 letters followed by 4 numbers is that ?– Isac
Yes. I tested it here, but for some reason it keeps giving error.
– Lucas Correia
I got it. It was a problem with string size. Thanks, Isac! It helped a lot, partner!
– Lucas Correia