0
I made a program that simulates a login and when converting the password that is int to string using sprintf it from segimentation falt, I tried to use itoa but it from the definition error
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char login[6]={0};
int passwd;
char senha[6]={0};
char logins[6]="Teste";
char senhas[6]="12345";
do{
printf("\n\tDigite o Login: ");
scanf("%s",login);
if((strcmp(login, logins) == 0))break;
else
printf("\tUsuario: %s Inválido..!!\n", login);
}while((strcmp(login, logins) != 0));
do{
printf("\n\tDigite sua senha: ");
scanf("%d",passwd);
sprintf(senha,"%s",passwd);
if((strcmp(senha, senhas) == 0))
printf("\n\tUsuario e Senha Válidos\n\tAcesso autorizado..!!!\n\n");
else
printf("\tSenha: %s Inválida..!!\n", senha);
}while((strcmp(senha, senhas) != 0));
return 0;
}
If the password is a
int
because it needs to be converted tostring
? If it’s supposed to be astring
why not readstring
directly ?– Isac
pq this is another way to use comparison to log in, and then need to check if the password is int convert to char* compare and log in if it is equal but not able to convert this password to string...
– dark777