|
-
January 25th, 2009, 09:47 PM
#1
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
-
January 25th, 2009, 10:51 PM
#2
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.
-
January 26th, 2009, 03:21 AM
#3
Re: Access Violation Error with cstring
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|