Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strncpy errors and don't know why.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Len=strlen(lpCmdLine);
strncpy(lpCmdSwitch,lpCmdLine,Len-strlen (lpCmdSwitchValue));


The lp vars are LPSTR's. It should work (I think) but when ever I pass anything but "0" it errors. My STR2 is initialized as NULL and have tried a terminator as well "\0" but it still errors.

Any guesses
 
You need to allocate memory for your variables.
LPSTR lpvar = malloc(size_t size) where size would be the amount of memory you need.

Hope that helps.

Tom-
 
Well, if you are coding C++, I recommand to use operator new instead of malloc !

For char array, use new[] and delete[] (do not forget [] of delete !)

David
 
the correct variant will be. It sure will work

strncpy(lpCmdSwitch,lpCmdLine,Len-strlen (lpCmdSwitchValue)+1); [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top