请问%[^\n]是什么意思?

gamefish7 2005-05-02 06:06:07
只见过%d,%s之类的,%[^\n]是什么意思,怎么理解??
程序段如下:
FILE *fd;
char b[100];

fd = fopen(b, "r");
fscanf(fd,"%[^\n] ",b);
if(b[0]!='P'|| b[1] != '3')
{
printf("%s is not a PPM file!\n", b);
exit(0);
}
...全文
900 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuhjnm_20001 2005-05-04
  • 打赏
  • 举报
回复
mark
xjp6688 2005-05-04
  • 打赏
  • 举报
回复
正则表达式
dvdface 2005-05-04
  • 打赏
  • 举报
回复
微软就喜欢乱改
visual4825 2005-05-03
  • 打赏
  • 举报
回复
第一次见
hszr99 2005-05-02
  • 打赏
  • 举报
回复
长见识了
zhousqy 2005-05-02
  • 打赏
  • 举报
回复
就是接收除\n之外的字符把。
DiyerYang 2005-05-02
  • 打赏
  • 举报
回复

学习中
antijpn 2005-05-02
  • 打赏
  • 举报
回复
一不小心用错马甲……
antijpn 2005-05-02
  • 打赏
  • 举报
回复
就知道是scanf的东西表示以'\n'结尾的一个string,并且不包括'\n'

如果直接用%s的话,那么只要出现一个whitespace(空格、回车都是),那么字符串到此就为止了,而这样的话,只有\n才能终结这个字符串……

其实和fgets没有什么差别(但是fscanf这个应该会慢一点……)
jerry 2005-05-02
  • 打赏
  • 举报
回复
这样的用法还真没见过
WingForce 2005-05-02
  • 打赏
  • 举报
回复
查到了
To read strings not delimited by space characters, a set of characters in brackets ([ ]) can be substituted for the s (string) type character. The corresponding input field is read up to the first character that does not appear in the bracketed character set. If the first character in the set is a caret (^), the effect is reversed: The input field is read up to the first character that does appear in the rest of the character set.

Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]. This is a common scanf function extension, but note that the ANSI standard does not require it.
-msdn
注意最后:This is a common scanf function extension, but note that the ANSI standard does not require it.
llf_hust 2005-05-02
  • 打赏
  • 举报
回复
不知道
chunhai12 2005-05-02
  • 打赏
  • 举报
回复
不知道,没见过
期待高手出现
WingForce 2005-05-02
  • 打赏
  • 举报
回复
看着象正则表达式。。。
不知道,没研究过
期待高手出现

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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