0
I have a string declared as follows:
char cpf[12];
I want to validate that the user typed only numbers when he typed ENTER.
I captured the value typed by the user like this:
gets(cpf);
Soon after, I call a function that traverses this array "Cpf", character by character, casting to convert string to int, in order to identify the presence of a non int.
The call went like this:
if ((valida_cnh_cpf(cpf)) = 1) {
printf("Erro, informe somente números para CPF\n");
system("pause");
system("cls");
menu();
}
And the function was declared so:
int valida_cnh_cpf(cpf_cnh) {
fflush(stdin);
int cpf_cnh_convertido[11];
int i;
for (i = 0; i <= strlen(cpf_cnh); i++) {
cpf_cnh_convertido[i] = (int) cpf_cnh[i];
if (isdigit(cpf_cnh_convertido[i])) {
return 0;
} else {
i = strlen(cpf_cnh) + 1;
return 1;
}
}
}
The problem is soon in the build. I get the following error pointing to the for line:
[Warning] Passing argument 1 of 'strlen' makes Pointer from integer without a cast
From what I understand, I have to cast somewhere. Could you help me identify?
Jefferson, thank you very much.
– Ângelo
@Angelo, in need, just keep asking good questions that good answers will sprout from the ground like weeds =)
– Jefferson Quesado