Capitalize string and return local variable

后端 未结 3 603
予麋鹿
予麋鹿 2020-12-22 05:16

I\'m trying to make a procedure that will capitalize a string, but I get junk values and a warning from gcc that I\'m returning the address of a local variable. Coming from

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 06:15

    You have two options in C.

    1) you can pass your function an pointer to the string and function will modify it and return void

    In this case you can just use the original string

    2) you can pass your function const char* and return char *, but then you need to malloc inside the function

    If you do a malloc inside function, you can then use the string (print it or do whatever you want), at the and of the program you call free

提交回复
热议问题