strcmp怎么用?

usr_src 2009-07-12 04:14:47
这个有指针的情况下是怎么用的啊??多谢!!我在写一个动态链表的程序,在查询姓名的时候,指针不知道该怎么用??多谢各位指点啊!!!
...全文
1761 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tommylee28 2009-07-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 usr_src 的回复:]
假如  struct student*p,结构体中有name【】;(strcmp(p->name,NULL)==0)是表示name为空吗?
[/Quote]
strcmp(p->name,NULL
传入指针为NULL程序会crash
wesleyluo 2009-07-12
  • 打赏
  • 举报
回复
留个印。
Fleeboy 2009-07-12
  • 打赏
  • 举报
回复
Walf_ghoul 2009-07-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 usr_src 的回复:]
假如 struct student*p,结构体中有name【】;(strcmp(p->name,NULL)==0)是表示name为空吗?
[/Quote]
lz对这个NULL是什么个理解,是表示p->name == "";这个意思吗,如果是这样那就比较strcmp(p->name,"")就好。
如果是想判断p->name(如果它是指针)指向空,那就直接判断,strcmp是比较两个字符串的值的。。
loveisbug 2009-07-12
  • 打赏
  • 举报
回复
你觉得传一个NULL会发生什么呢?

退一步,strcmp比较的是两个指针所指内容,而不是比较两个指针所指向的地址。
usr_src 2009-07-12
  • 打赏
  • 举报
回复
假如 struct student*p,结构体中有name【】;(strcmp(p->name,NULL)==0)是表示name为空吗?
ies_sweet 2009-07-12
  • 打赏
  • 举报
回复

strcmp( )
NAME
strcmp( ) - compare two strings lexicographically (ANSI)

SYNOPSIS

int strcmp
(
const char * s1, /* string to compare */
const char * s2 /* string to compare s1 to */
)

DESCRIPTION
This routine compares string s1 to string s2 lexicographically.


INCLUDE FILES
string.h


RETURNS
An integer greater than, equal to, or less than 0, according to whether s1 is lexicographically greater than, equal to, or less than s2, respectively.

usr_src 2009-07-12
  • 打赏
  • 举报
回复
这种比较我明白!!不过不是我想要知道的!!多谢!!~~
loveisbug 2009-07-12
  • 打赏
  • 举报
回复
请参考:http://en.wikipedia.org/wiki/Strcmp
Nio96 2009-07-12
  • 打赏
  • 举报
回复
strcmp传进去的就是指针
大前置 2009-07-12
  • 打赏
  • 举报
回复
int strcmp( const char *str1, const char *str2 );


功能:比较字符串str1 and str2, 返回值如下:

返回值
解释

less than 0
str1 is less than str2

equal to 0
str1 is equal to str2

greater than 0
str1 is greater than str2

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧