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

strchr的返回值

时间:2014-11-11 19:18:59      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   color   ar   os   使用   sp   div   

返回值是查找的字符做为首地址,返回的是一个字符串如果我们想提取这个位置开始的某一个字符的时候只需要使用指针数组就ok了

#include<string.h>

#include<stdio.h>
int main(void)
{
char string[17];
char*ptr,c=‘:‘;
strcpy(string,"Thisis:string");
ptr=strchr(string,c);
if(ptr)              {
printf("Thecharacter%cisatposition:%s\n",c,ptr);
printf("%c",ptr[1]);
}
else
printf("Thecharacterwasnotfound\n");


getch();

return 0;}


功能:查找字符串s中首次出现字符c的位置
说明:返回首次出现c的位置的指针,返回的地址是字符串在内存中随机分配的地址再加上你所搜索的字符在字符串位置,如果s中不存在c则返回NULL
返回值:成功则返回要查找字符第一次出现的位置,失败返回NULL

strchr的返回值

标签:style   http   io   color   ar   os   使用   sp   div   

原文地址:http://blog.csdn.net/songjunyan/article/details/41013443

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