C语言gets()函数得到的字符串结尾的是什么?

wangqi_9225 2016-07-27 09:46:21
今天用了C语言gets()函数,网上查了下说结尾将‘\n’换成'\0',但是我用了不对,调试的时候输入字符串'SAD',看了下数组s[](gets(s),s[]是定义的数组),s[3]= 0‘\000’,请问这是怎么回事
...全文
1628 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
NotSimpleEasy 2016-07-29
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
查MSDN是Windows程序员必须掌握的技能之一。
真·skysys 2016-07-28
  • 打赏
  • 举报
回复
gets() 函数是 按 行 读入。读入到回车结束。 在内部实现中用'\0'代替回车
赵4老师 2016-07-27
  • 打赏
  • 举报
回复
查MSDN是Windows程序员必须掌握的技能之一。
paschen 2016-07-27
  • 打赏
  • 举报
回复
wang0635 2016-07-27
  • 打赏
  • 举报
回复
s[3]= 0‘\000’,没问题啊 s[3]的值是0 写成字符型就是‘\000’,转义字符,值是八进制的0
flying_music 2016-07-27
  • 打赏
  • 举报
回复
怎么不对啊,就是‘\0’啊,‘\000’就是八进制的0的意思,也就是十进制的0,而‘\0’对应的ASCII码就是0,是一回事儿
「已注销」 2016-07-27
  • 打赏
  • 举报
回复
char * gets ( char * str ); Get string from stdin Reads characters from the standard input (stdin) and stores them as a C string into str until a newline character or the end-of-file is reached. The newline character, if found, is not copied into str. A terminating null character is automatically appended after the characters copied to str.
小灸舞 版主 2016-07-27
  • 打赏
  • 举报
回复
gets 是读取换行符的,不过它会把换行符转换为'\0'
http://www.cplusplus.com/reference/cstdio/gets/?kw=gets

70,023

社区成员

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

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