When i tried using the strlen inside the for loop, it gives me the following warning msg. I would like to know why this happend ??
"warning C4018: '<' : signed/unsigned mismatch"
Code:for(i=1; i < strlen(inputx); i++)
When i tried using the strlen inside the for loop, it gives me the following warning msg. I would like to know why this happend ??
"warning C4018: '<' : signed/unsigned mismatch"
Code:for(i=1; i < strlen(inputx); i++)
warnings are warning.. just ignore them..
but if you want an explanation:
'i' probably is of the type signed int..
because strlen always returns a positive value, strlen returns an unsigned int..
to fix this warning: i < (int) strlen(inputx) --> typecasting
Last edited by zuiplap; 05-05-2004 at 06:06 AM.
> warnings are warning.. just ignore them..
Remarkably bad advice IMO (who isn't joking)
> warning C4018: '<' : signed/unsigned mismatch"
Well what do you think would happen if you compared say -1 (a signed number) with an unsigned number?
> strlen returns an unsigned int..
It returns a size_t
The easy fix is to declare
Code:size_t i; for(i=1; i < strlen(inputx); i++)
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ok, only ignore them when you know there is no harm
here you can ignore the warning: here i > 0 always so there is no problem ignoring this warning..
i was only guessing strlen returned an unsigned int.. i was to lazy to look it up.. sorry about that..
now you have two solutions.. the point is, there is a type mismatch.. either change type of i, or use typcasting with one of them..
btw. Salem, size_t, was is it? i remember seeing it in some functionheaders.. explain plz
edit: wow, i went overload with the smileys
>ok, only ignore them when you know there is no harm
Why not fix all warnings so that they don't hide real errors?
>i remember seeing it in some functionheaders.. explain plz
size_t is the "unsigned integer type of the result of the sizeof operator".
size_t is a typedef for portability. It might be different on some machines