I'm re-learning some programming to use at work (haven't done C in 11 years and am learning C++)...
I'm returning a pointer from a function and when it's returned, the target char array has some extra garbage characters at the end.
So here's the function I've written (with much stripped away):
pMydate points to a 'char MyOtherArray[17]' outside of the function...
Expand|Select|Wrap|Line Numbers
- char* asciDate(char* pMydate)
- {
- char myarray[17];
- char* pMyarray;
- // some code here that puts the characters in the string...
- pMyarray = myarray;
- strncpy(pMydate, pMyarray, 17);
- return pMydate;
- }
If I try to output pMydate to stdio or a file, it includes the garbage. (i.e. cout << pMydate;)
Why are 2 garbage characters showing up where the pointer is pointing?
Platform = WinXP
Using Microsoft Visual C++ (Visual Studio 8)