gets()何时返回空指针

infinity2021 2011-10-14 09:17:29
输入空行能不能返回空指针,就是不输入,直接按回车。
另外什么情况下返回空指针,如何输入?
...全文
163 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2011-10-14
  • 打赏
  • 举报
回复
Ctrl+Z,Enter
诶呦 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 aurora_ 的回复:]
那是不是用%p格式打印gets()的返回值会显示是0啊?
[/Quote]
这个0是数值,空指针是指没有分配内存
诶呦 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 aurora_ 的回复:]
如果输入空行的话
[/Quote]
输入空行就是出入'\0'
infinity2021 2011-10-14
  • 打赏
  • 举报
回复
求解啊
infinity2021 2011-10-14
  • 打赏
  • 举报
回复
如果输入空行的话
infinity2021 2011-10-14
  • 打赏
  • 举报
回复
那是不是用%p格式打印gets()的返回值会显示是0啊?
hu7324829 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 aurora_ 的回复:]
引用 1 楼 anyidan 的回复:

char *gets(char *s)
gets reads the next input line into the array s; it replaces the terminating newline with '\0'. It returns s, or NULL if end of file or error occurs.
那输入空行……
[/Quote]
If the End-of-File is encountered and no characters have been read, the contents of str remain unchanged and a null pointer is returned.
对, 空行会返回NULL
Ol_lO 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 aurora_ 的回复:]

引用 1 楼 anyidan 的回复:

char *gets(char *s)
gets reads the next input line into the array s; it replaces the terminating newline with '\0'. It returns s, or NULL if end of file or error occurs.
那输入空……
[/Quote]
不会,只有遇到文件结尾或者发送错误时
infinity2021 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 anyidan 的回复:]

char *gets(char *s)
gets reads the next input line into the array s; it replaces the terminating newline with '\0'. It returns s, or NULL if end of file or error occurs.
[/Quote]那输入空行是否返回空指针?
AnYidan 2011-10-14
  • 打赏
  • 举报
回复
char *gets(char *s)
gets reads the next input line into the array s; it replaces the terminating newline with '\0'. It returns s, or NULL if end of file or error occurs.

69,371

社区成员

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

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