关于%n

time_time_time 2011-07-20 11:54:31
gcc下%n 不起作用

int len=1;
printf("%d%n\n",123,&len);


printf("%d",len);//len结果不变

网上搜不到
codeblocks 下自带gcc
...全文
75 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ForestDB 2011-07-20
  • 打赏
  • 举报
回复
CodeBlocks是带gcc的编译器,但它的库是基于Windows的。
ForestDB 2011-07-20
  • 打赏
  • 举报
回复

$ cat x.c
# include <stdio.h>

int main()
{
int len = 0;
printf("%d%n\n", 123, &len);
printf("%d\n", len);

return 0;
}

$ ./x
123
3

风吹PP凉SS 2011-07-20
  • 打赏
  • 举报
回复
+1[Quote=引用 1 楼 peach_zeng 的回复:]
%n是.....输出什么格式的???
[/Quote]
赵4老师 2011-07-20
  • 打赏
  • 举报
回复
man printf

int len=-1;
len=printf("%d\n",123);
printf("%d",len);

len=-1;
printf("%d%n",123,&len);fflush(stdout);
printf("%d\n",len);
至善者善之敌 2011-07-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 peach_zeng 的回复:]
%n是.....输出什么格式的???
[/Quote]

+++1
peach_zeng 2011-07-20
  • 打赏
  • 举报
回复
%n是.....输出什么格式的???
time_time_time 2011-07-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 forestdb 的回复:]

CodeBlocks是带gcc的编译器,但它的库是基于Windows的。
[/Quote]

可能是这个原因 !
time_time_time 2011-07-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhao4zhong1 的回复:]

man printf

int len=-1;
len=printf("%d\n",123);
printf("%d",len);

len=-1;
printf("%d%n",123,&len);fflush(stdout);
printf("%d\n",len);
[/Quote]
这个好像和缓存没有关系 因为 gcc下根本都没有更改len的值 而且没有什么错误提示

69,371

社区成员

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

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