#include <iostream> using namespace std; int main() { char message1[]="Original message"; strcpy(message1,"different");//different0essage0 cout<<message1<<endl;//different char message2[]="Original message"; // strcpy(message2,"A different message");//运行时错误 所以要复制的字符串要小于等于目的数组长度 cout<<message2<<endl; char *p1="abc"; char *p2="abcd"; cout<<strcmp(p1,p2)<<endl;//-1 char p3[]="abc"; char p4[]="abcde"; strncpy(p3,p4,3); cout<<p3<<endl; strncpy(p3,p4,4);//当源字符串长度大于目的字符串时,只有sizeof(dst)个会赋值到目的数组中,且不会以'\0'结尾 cout<<p3<<endl; p3[3]='\0'; cout<<p3<<endl; }
void main() { cout<<lookup_keyword("while",keyword,5)<<endl; char buff[10]="zhangwen"; char buff2[10]={'0'}; memcpy(buff2,buff,5);//复制buff的前5个元素到buff2 cout<<buff2<<endl;//zhang memset(buff,'a',3);//将buff的前三个内存位置的值设置为'a' cout<<buff<<endl;//aaangwen cout<<memcmp(buff,buff2,3)<<endl;//a<z所以打印-1 char *p=(char*)memchr(buff,'n',10);//查找buff中是否有字符‘n’有则返回指针 无则返回NULL cout<<*p<<endl;//打印出n }