0
I need to count the total number of characters present in any word without the function strlen()
.
First I performed the word reading, after using a for
to go through the word, within the for
I used the while
to add my counter while palavra
in position [i]
is different from null \0
, however an error is happening, the program even opens, but does not execute anything.
On the console it is reported that I am trying to compare a pointer to an integer, how could I solve this?
#include <stdio.h>
#include <string.h>
main()
{
char palavra[20];
int tam=0 ,i;
printf("\n Digite uma palavra: ");
gets (palavra);
for (i=0; i < palavra ;i++)
{
while(palavra[i] != '\0')
{
tam ++;
}
}
printf("\n %d", tam);
}
i < palavra
,i
is a whole andpalavra
is a pointer, but even tidying up this will have problems with thewhile
that will be infinite. Considering the word"abacate"
,i
would start at zero and thewhile
will perform whilepalavra[0]
is different from'\0'
, which is always.– Woss