Freeing malloc will not erase char data

前端 未结 4 1881
悲&欢浪女
悲&欢浪女 2021-01-29 07:27

I made a smaller scenario of my bigger problem. What I try to do is pass a string to a function which will make a new string out of it. However I ran into some problems.

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 08:07

    Try changing

    strcat(buff, "."); 
    

    into

    strcpy(buff, "."); 
    

    Or alternativly initialise buff when declaring it like so:

     char buff[1024] = "";
    

提交回复
热议问题