strncpy(char* s1,const char *s2,int n) 和 strchr(cosnt char *s,char c)

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5      char s1[10] = "abcd";
 6      char s2[10] = "ABCDEF";
 7      printf("s1 =  %s\ns2 = %s\n",s1,s2);
 8      strncpy(s1,s2,3);
 9      printf("s1 = %s\ns2 = %s\n",s1,s2);
10 
11      char string[17];
12      char *ptr,c = 'r';
13      strcpy(string,"This is a string");
14      ptr = strchr(string,'i');
15      if(ptr)
16           printf("the character %c is at position:%s\n",c,ptr);
17      else
18           printf("the character was not found\n");
19 
20 
21      return 0;
22 }
23 
24 s1 =  abcd
25 s2 = ABCDEF
26 s1 = ABCd
27 s2 = ABCDEF
28 the character r is at position:is is a string
29 Press any key to continue

 

posted @ 2015-03-20 13:41  &苍云  阅读(379)  评论(0编辑  收藏  举报