non-pointer type `char' from NULL的问题
#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;
这个警告是什么意思啊?
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;
这个警告是什么意思啊?
...全文
相关推荐
C_pointer_chtp4_07.pdf
It is read as "countPtr is a pointer to int" or "countPtr points to an object of type int."
C语言18个经典问题答录
### C语言18个经典问题答录#### 1. 这样的初始化有什么问题?`char *p = malloc(10);` 编译器提示“非法初始式”云云。
指针(pointer)——C-C++的精髓
- **注意事项**:虽然指针功能强大,但也容易引发错误(如野指针问题、内存泄漏等),因此在使用过程中需要特别小心。
char*转为LPCWSTR
**缓冲区大小**:在转换时要注意缓冲区的大小,以避免缓冲区溢出等问题。
pointer_字符串_指针_
每读取一行,就动态分配一个新的内存块来保存该行内容,并创建一个新节点,其数据部分为字符串,指针部分指向下一个节点(或NULL表示链表末尾)。


