1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 char s1[100]="12345";
6 char s2[100]="abcdefg";
7 char s3[100]="ABCDE";
8 strncat(s1,s2,3);
9 cout<<s1<<endl;///输出12345abc
10 strncpy(s1,s3,3);
11 cout<<s1<<endl;///输出ABC45abc
12 strncpy(s2,s3,6);
13 cout<<s2<<endl;///输出ABCDE
14 cout<<strncmp(s1,s3,3)<<endl;///输出0
15 char *p=strchr(s1,'B');
16 if(p)
17 cout<<p-s1<<","<<*p<<endl;///输出1,B
18 else
19 cout<<"Not Found"<<endl;
20 p=strstr(s1,"45a");
21 if(p)
22 cout<<p-s1<<","<<p<<endl;///输出3,45abc
23 else
24 cout<<"Not Found"<<endl;
25 cout<<"strtok usage demo:"<<endl;
26 char str[]="- This,a sample string,ok.";
27 p=strtok(str," ,.-");
28 while(p!=NULL)
29 {
30 cout<<p<<endl;
31 ////////////输出
32 /*
33 This
34 a
35 sample
36 string
37 ok
38
39 */
40 p=strtok(NULL," ,.-");
41 }
42 return 0;
43 }