N
No Such Luck
I have a function which requires me to loop from the end of a string to
the beginning on a char by char basis:
int foo (char string[])
{
unsigned int i;
for(i = strlen(string); i >= 0; i--)
{
/* do something */
}
return 1;
}
Here is my problem. strlen() returns an unsigned value, so if I use a
signed loop variable, I receive a warning: "'<' : signed/unsigned
mismatch"
However, if I use a unsigned loop variable to compare against the
correct return type of strlen(), the loop never ends. The value of 'i'
turns from 0 to the highest unsigned value possible.
Any ideas on how to solve this problem, and not receive the warning?
Thanks,
P.S. Traversing the string forwards is not an option.
the beginning on a char by char basis:
int foo (char string[])
{
unsigned int i;
for(i = strlen(string); i >= 0; i--)
{
/* do something */
}
return 1;
}
Here is my problem. strlen() returns an unsigned value, so if I use a
signed loop variable, I receive a warning: "'<' : signed/unsigned
mismatch"
However, if I use a unsigned loop variable to compare against the
correct return type of strlen(), the loop never ends. The value of 'i'
turns from 0 to the highest unsigned value possible.
Any ideas on how to solve this problem, and not receive the warning?
Thanks,
P.S. Traversing the string forwards is not an option.