如何获得一个const char *功能正常工作? [英] How to get a const char* function to work?
问题描述
所以我有这个字符常量* blahblahblah(为const char * S)
功能,但是当我尝试使用 strcat的(S,)
或返回小号[K]
在它上面说
So I have this char const* blahblahblah(const char* s)
function but when I try to use strcat(s, " ")
or return s[k]
in it it says
const char*s
Error: argument of type "const char*" is incompatible of parameter of type "char"
如果我想留的功能是什么,我应该在我的参数的变化,以便为它工作?
If I want the function to stay as is what should I change in my parameters in order for it to work?
推荐答案
如果你声明为const char * S,那么你不应该写的strcat(S,),因为strcat的修改秒。
If you declare const char* s, then you should not write strcat(s, " "), because strcat modifies s.
如果你声明字符常量* reverseWordsOnly,那你为什么返回S [K]? S [k]的不是指针。
if you declare char const* reverseWordsOnly, then why do you return s[k]? s[k] is not a pointer.
编辑:
这取决于你想要做什么。我不知道你想在这个函数该怎么做。
This depends on what you want to do. I don't know what you want to do in this function.
如果您不要修改s,则宣告为const char * s是确定。
If you don't modify s, then declaring const char* s is OK.
如果您想返回字符常量*,那么也许你想返回&安培; S [K]而不是S [K]
If you want to return char const *, then maybe you want to return &s[k] instead of s[k].
也许你想返回的char *,那么你可以施放和放大器; S [K]使用(字符*)及; S [K]
Maybe you want to return char *, then you can cast &s[k] using (char *)&s[k].
这篇关于如何获得一个const char *功能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!