LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1097|回复: 9

看不懂strrchr(),请帮忙。

[复制链接]
发表于 2004-2-2 23:53:37 | 显示全部楼层 |阅读模式
Find the first occurrence of a character in a string


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main( void )
  5.   {
  6.     printf( "%s\n", strrchr( "/usr/include", '/' ) );
  7.     if( strrchr( "abcdeabcde", 'x' ) == NULL )
  8.       printf( "NULL\n" );
  9.     return EXIT_SUCCESS;
  10.   }
  11. /forum/c/app.tmp# ./a.out
  12. /include
  13. NULL
  14. /forum/c/app.tmp#
复制代码


那结果好奇怪阿。??
发表于 2004-2-3 08:00:46 | 显示全部楼层
strrchr(const char * s,int c)返回一个char*,指向最后一次出现的c,如果s中没有c,则返回NULL
发表于 2004-3-21 00:28:26 | 显示全部楼层
结果没问题
发表于 2004-3-21 20:38:14 | 显示全部楼层
"/usr/include", '/'

这里只要求找出/

结果是却是;/include
 楼主| 发表于 2004-3-23 08:13:56 | 显示全部楼层
最初由 release 发表
"/usr/include", '/'

这里只要求找出/

结果是却是;/include


帮忙阿!就是这个疑问。
发表于 2004-3-23 09:18:40 | 显示全部楼层
[PHP]函数名: strrchr
功  能: 在串中查找指定字符的最后一个出现
用  法: char *strrchr(char *str, char c);
程序例:

#include <string.h>
#include <stdio.h>

int main(void)
{
   char string[15];
   char *ptr, c = 'r';

   strcpy(string, "This is a string");
   ptr = strrchr(string, c);
   if (ptr)
      printf("The character %c is at position: %d\n", c, ptr-string);
   else
      printf("The character was not found\n");
   return 0;
}

[/PHP]
发表于 2004-3-23 19:00:49 | 显示全部楼层
这个没什么问题呀?
你需要的是什么呢?
发表于 2004-3-23 19:06:09 | 显示全部楼层
夷??这个函数有什么用?找出第一个发生的字符在一个字符串?

同样的看不懂楼主的程序的结果。还有其他的例子吗?
发表于 2004-3-23 19:19:39 | 显示全部楼层
从一个字符串中反向查找第一个出现指定字符的位置。在正常情况下,应该是从用面开始找,出现的第一个指定字符的位置,如果是希伯来文的话,可能是从左面找的。
发表于 2004-3-23 19:31:24 | 显示全部楼层
Find the first occurrence of a character in a string
谢谢!!这个注释没有说明白哦。。看来编者表达得不清楚。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表