Is it possible to modify a string of char in C?

前端 未结 9 1421
小蘑菇
小蘑菇 2020-11-22 09:08

I have been struggling for a few hours with all sorts of C tutorials and books related to pointers but what I really want to know is if it\'s possible to change a char point

9条回答
  •  天命终不由人
    2020-11-22 09:52

    You could also use strdup:

       The strdup() function returns a pointer to a new string which is a duplicate of the string  s.
       Memory for the new string is obtained with malloc(3), and can be freed with free(3).
    

    For you example:

    char *a = strdup("stack overflow");
    

提交回复
热议问题