Originally Posted by
Tony Flury
To me,
Code:
while(result != NULL) {
val=strtok(buf,"=");
val=strtok(NULL,"=");
val[strlen(val)-1]=0;
result[0]=val;
break;
}
is confusing - not saying this is the souce of the problem, but it does not make sense to me. You seem to be tryig to find the 2nd equals sign in val (i.e. the two strtok).
I think this line is superfluous :
Code:
val[strlen(val)-1]=0;
As the definition of strlen means that there is already a NUL character at position strlen(val)-1.
also the test in the loop seems wrong to me.
Doesn't the definition of strlen mean that there is a NULL character at position strlen(val), and a valid character at strlen(val) -1 (if and only if, of course, strlen(val) > 0)?
PHP Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *string = "test";
printf("%d\n%d - %d\n", strlen(string), string[strlen(string)], string[strlen(string)-1]);
return 0;
}
Output:
So, effectively, writing
PHP Code:
val[strlen(val)-1] = 0;
means deleting the last non-null character from the string, doesn't it?
Bookmarks