non-pointer type `char' from NULL的问题

eugenekim eugenekim 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
using namespace std;

char *strncat(char *destination, const char *source, int n);
int main()
{
char *str1=new char[256];
char *str2=new char[256];
cout << "Input string1 and Press Enter: " << endl;
cin.getline(str1,256,'\n');
cout << "Input string2 and Press Enter: " << endl;
cin.getline(str2,256,'\n');
strncat(str1,str2,2);
cout << "The result is:" << endl << str1;
return 0;
}

char *strncat(char *destination, const char *source, int n)
{
char *original=destination;
int i=0;
while (*destination)
destination++;
while ((i++<n) && (*destination++=*source++))
;
if (i>n)
*destination=NULL;
return original;
}

g++ strncat.cpp -g -o strncat
出现警告:
strncat.cpp: In function `char* strncat(char*, const char*, int)':
strncat.cpp:27: warning: assignment to non-pointer type `char' from NULL
strncat.cpp:27: warning: argument to non-pointer type `char' from NULL

第27行是:*destination=NULL;
这个警告是什么意思啊?
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
eugenekim
C++ 语言 65,214 成员 250,514 内容