- 论坛徽章:
- 0
|
原帖由 poper 于 2006-9-7 00:41 发表
大概看了一下,有点感想说出来大家讨论一下.
楼主的代码写的不规范啊.比如char* s=0;这样的CODE...
还有,在void Rstrchr(char * s, int x, char ** d)里好象有个BUG,s的最后一个字符不会被搜索的...
规范这东西仁者见仁了,习惯就好,何况规范是人自己定的。我不太遵循
依poper高见,定义指针初始化为空值如何写比较规范呢?贴出来让咱学习学习
另外Rstrchr经测试无BUG
- /* 这是测试代码 */
- #include <string.h>
- #include <stdio.h>
- void Rstrchr(char * s, int x, char ** d)
- {
- int len = strlen(s) - 1;
- while(len >= 0) {
- if(x == s[len]) {(*d) = s + len; return;}
- len--;
- }
- (*d) = 0;
- }
- int main(int argc, char ** argv)
- {
- char * p = 0;
- Rstrchr(argv[1], 'a', &p);
- if(p) printf("%s\n", p);
- return 0;
- }
复制代码
/* 这是测试运行结果
test@local:/source/example/c$ gcc rstrchr.c
test@local:/source/example/c$ ./a.out wehasdf
asdf
test@local:/source/example/c$ ./a.out asdf
asdf
test@local:/source/example/c$ ./a.out weha
a
test@local:/source/example/c$ ./a.out wehsdf
*/
无论字符a是在字符串的哪个位置都是可以正常被搜索出来的
能不把你那里的测试结果贴出来? |
|