Code:
//for lines larger or equal than the size limit....
if (orig >= (PARSE_SIZE_LIMIT - 1))
{
for (x = 0; x <= (PARSE_SIZE_LIMIT - 1); x++)
{ subject[x] = userstring[x]; }
}
//for lines less than the size limit....
if (orig < (PARSE_SIZE_LIMIT - 1))
{
for (x = 0; x <= orig; x++)
{ subject[x] = userstring[x]; }
}
subject[x+1] = '\0';//add terminating null character
You have a buffer overflow in both cases. Use a debugger to step through your loops to find out the value of "x" after both loops.
You really need to be more careful if you use <= in for-loops.
Code:
//** this is where strtok() is used **
//copy the first word in the string (must be done to find the next words)
if(word == 1)
{
p = strtok(subject,w);
strcpy(target,p);
}
//copy all the next words (sequencially) in the string
if(word > 1)
{
p = strtok(NULL,w);
strcpy(target,p);
}
When word > 1 strtok returns garbage or NULL because you never initialise it with a string to tokenize. You only do that when word == 1.
Furthermore, "w" is not a C-string but a pointer to a single character.
Bye, Andreas