how to get timestamp in c

后端 未结 5 1080
情话喂你
情话喂你 2021-01-19 10:53

I want to get timestamp for my log in c. i have written a function to get timestamp. But when i return the variable i m getting different value.

My code:

<         


        
5条回答
  •  春和景丽
    2021-01-19 11:26

    The string you're returning is an automatic variable. When you exit the function accessing this variable is impossible. According to the specs it's undefined behavior. Use malloc to allocate the string and you'll be fine. Just don't forget to free it afterwards.

提交回复
热议问题