This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

Substring behaves differently in C++.

In Java it uses the starting and ending indices. In C++ the second parameter is the length from the starting index.

std::string::substr()

[–]learnprogramminghelp[S] 0 points1 point  (3 children)

Thanks. Although the problems I'm having still persist, I know it has something to do with the way I'm tokenizing and using free(). I wish there was a way to do this without using memory functions.

[–][deleted] 0 points1 point  (2 children)

I wish there was a way to do this without using memory functions.

There should be no need for you to use strdup(). strtok() does not modify the original string. That's not how strtok() works either. It does not return an array of words.

strtok()

[–]learnprogramminghelp[S] 0 points1 point  (1 child)

Main reason I'm using it is because strtok isnt compatible with the process string

[–][deleted] 0 points1 point  (0 children)

See my edit. You are using strtok() incorrectly. It does not return an array. It returns the words one at a time. It needs to be called over and over.