码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-03-20 14:12:37      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

 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

 

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

标签:

原文地址:http://www.cnblogs.com/kirsten/p/4353422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!