[Solved] C Program – How to get the second occurrence in strtok()? [closed]


You change the first argument of strtok to NULL. It would look like this:

strtok(NULL, " = ");

Of course, you would still have to keep your call to strtok(myfile, " = "); but any subsequent calls to strtok with NULL as the first argument will continue from the last point of the previously specified string.

Example:

printf("%s", strtok(myfile, " = ");     // prints "/www/test.php"
printf("%s", strtok(NULL, " = ");       // prints "24323"

You also cannot compare a string to an integer. You need to use atoi like so:

if (st.st_size != atoi(def_size) {
    printf("File size doesn't match\n");
}

3

solved C Program – How to get the second occurrence in strtok()? [closed]