Access Violation Error with cstring
My declaration:
Code:
char * tempToken;
tempToken = "";
What's giving the error:
Code:
strcpy_s(tempToken, tempInt, tempString);
Both tempInt and tempString have valid values. I have a struct called Node that has a token and a link to another Node (for a linked list). I've tried
Code:
strcpy_s(v->token, tempInt, tempString);
And the error THAT gave me something along the lines of DST != NULL && sizeInByte > 0
I've tried char tempToken[100]; as a declaration and char *tempToken = ""; and char * tempToken = malloc(sizeof(char)*100);
I'm banging my head against the wall here. Anyone tell me what I'm doing wrong?
Thanks in advance,
Lang
Re: Access Violation Error with cstring
Code:
char * tempToken;
tempToken = "";
You've just pointed tempToken at a literal string. An empty one, but a literal nonetheless. Literal strings are allowed to live in a read-only portion of memory, and usually do on modern compilers.
Code:
strcpy_s(tempToken, tempInt, tempString);
Now you've just attempted to modify read-only memory.
What you should have done instead is allocate memory for tempToken and the copy in the literal string, so that you'd have modifiable memory to work with. Or better yet, just use a std::string so that you don't have to concern yourself with such things.
Re: Access Violation Error with cstring
Quote:
I'm banging my head against the wall here. Anyone tell me what I'm doing wrong?
Then I suggest a good C++ book: http://www.codeguru.com/forum/showthread.php?t=231039.