[...]
edit: cut away part that no longer applies
Some advice:
1. Read the full reference on the function
ctime()
and make sure you understand it. Here's a link :
http://www.cplusplus.com/reference/clibrary/ctime/ctime/[
^]
2. The buffer containing the string that ctime() returns is statically allocated and shared with other functions within this library. it may therefore be overwritten later and you cannot rely on it to maintain any modifications you apply to it. More importantly,
you do not know which functions access the buffer and in what way - any modification you make - and especially overwriting the terminating 0 - may well cause them to behave abnormally or even crash your app!
3. In short, never try to modify a C style string returned from a library function. At least not unless the function documentation explicitely states that you may do so. And even then, do not do it unless you understand C style strings:
read a book or tutorial on how to use them!
4. To address your problem, if you need a modified version of the output of
ctime()
, do the following:
- determine the total length of the modifed string
- add 1 for the terminating 0 character
- allocate a new C style string of that length
- copy the bits of the
ctime()
return value that you want into that new string.
- add the bits that you want modified
- when you're done with that modified string, release it from memory
I'm not going to write the actual code for that, because before I do I want you to read up on C strings and the string functions. Theere's no point in giving you the code if you fail to understand the meaning of every single function therein.