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++)
Printable View
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
> 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++)
:)
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 :D
>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