0
Guys, I need a little help to check if the email you typed ends with "@usp.br".
Here’s the code I’ve tried:
/* pega o tamanho total do email digitado */
int tamanho = strlen(email);
/* a partir do tamanho do email, comece a contar nos ultimos 7 caracteres -> que deve terminar em "@usp.br" */
int ultimos = email[tamanho-7]; /* -> se o email tiver 20 caracteres, comece do indice 13 */
char verifica[7] = "@usp.br";
int k=0;
for(i=0; i < 7; i++){
/* exemplo */
/* comece a comparar no indice 13, que deve conter a letra "@" */
if(email[tamanho-7] == verifica[k]){
k++;
continue;
}
else{
printf("Email digitado incorreto! Digite um email que termine com '@usp.br'!");
}
//k++;
}
This code doesn’t make any sense, and I doubt it will even do anything close to what you want. Anyway, I did not see a doubt there, just a request for help that is not in the scope of the site. Try to improve this so we can help.
– Maniero
Wouldn’t it be easier to do
if (strcmp(email+(strlen(email)-7), "@usp.br") == 0)
? Ensuring it is at least 7 characters clear– Isac