简单问题~有关SCANF里的转意字符!

pdaliu 2003-08-21 05:20:50
在SCANF里/n是什么意思?
比如:
scanf("%d %d\n",&a,&b);
scanf("%d %d %d",&c,&d&,&e);
...全文
100 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixplayer 2010-06-08
  • 打赏
  • 举报
回复
空白字符:空白('');制表符('\ t')方法;或换行符('\ n')的。一个空白字符scanf是导致阅读,但不能存储,所有连续的白色空间中的字符输入到下一个非空白字符。一个空白的格式匹配任何字符数(包括0)和空白字符组合输入。
pdaliu 2003-09-05
  • 打赏
  • 举报
回复
我英文不好~有人能给翻译一下吗?
紫郢剑侠 2003-08-24
  • 打赏
  • 举报
回复
n也是换行的意思,
和输入中的\n匹配
你输入的时候也要输入一个回车的
test7979 2003-08-23
  • 打赏
  • 举报
回复
仔细看这段话,:)
test7979 2003-08-23
  • 打赏
  • 举报
回复
White-space characters: blank (' '); tab ('\t'); or newline ('\n'). A white-space character causes scanf to read, but not store, all consecutive white-space characters in the input up to the next non–white-space character. One white-space character in the format matches any number (including 0) and combination of white-space characters in the input.
test7979 2003-08-23
  • 打赏
  • 举报
回复
按照MSDN的文档,\n 仅仅是过滤空白符号,所以答案应当是

a=1 b=2 c=3 d=4 e=5
pdaliu 2003-08-23
  • 打赏
  • 举报
回复
比如:
scanf("%d %d\n",&a,&b);
scanf("%d %d %d",&c,&d&,&e);

输入:
1 2 3
4 5 6
结果:
a=1 b=2 c=4 d=4 e=6吗?
GhostAdz 2003-08-22
  • 打赏
  • 举报
回复
\n也是换行的意思,
和输入中的\n匹配
你输入的时候也要输入一个回车的
playboyxp 2003-08-22
  • 打赏
  • 举报
回复
\n就是一个强制换行,相当于打了个回车
pdaliu 2003-08-22
  • 打赏
  • 举报
回复
还是不明白~
ianzy 2003-08-21
  • 打赏
  • 举报
回复
所谓匹配的意思是在 scanf 中出现了这个字符后则 scanf 一定会在输入字符串中寻找这个字符,在这个字符前的所有东西都丢掉,这个字符也丢掉,然后再进行后面的输入。在楼主的这个例子里 \n 放在最后面所以是无意义的。
test7979 2003-08-21
  • 打赏
  • 举报
回复
好象并不匹配的,scanf只是读进来,然后忽略掉

A format specification has the following form:

%
  • [width] [{h | l | I64 | L}]type

    The format argument specifies the interpretation of the input and can contain one or more of the following:

    White-space characters: blank (' '); tab ('\t'); or newline ('\n'). A white-space character causes scanf to read, but not store, all consecutive white-space characters in the input up to the next non–white-space character. One white-space character in the format matches any number (including 0) and combination of white-space characters in the input.
    Non–white-space characters, except for the percent sign (%). A non–white-space character causes scanf to read, but not store, a matching non–white-space character. If the next character in stdin does not match, scanf terminates.
    Format specifications, introduced by the percent sign (%). A format specification causes scanf to read and convert characters in the input into values of a specified type. The value is assigned to an argument in the argument list.
fupa0 2003-08-21
  • 打赏
  • 举报
回复
/n?
原字符吧
\n是换行
看一下转义字符表,有特定意义的不多
随便哪一本c教材里面都有
ianzy 2003-08-21
  • 打赏
  • 举报
回复
\n也是换行的意思,和输入中的\n匹配。

69,371

社区成员

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

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