如何确定输出缓冲区的大小 [英] How to determine the size of an output buffer

查看:129
本文介绍了如何确定输出缓冲区的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,让我们说我有一个充满异国情调的操作系统,限制了多少奖金。

标准输出。我什么时候去...


#include< stdio.h>


int main(无效){

int i = 0;


for(i = 0; i< 10; i ++){

printf(" a \ n") ;

}

返回0;

}

我得到这个....

[cdalten @ localhost~] $ ./out

a

a

a

a

a

a

a

a

a

a

但是现在,我将printf()更改为

printf(a test\ n);


现在当我运行

#include< stdio.h>


int main(void){

int i = 0;


for(i = 0; i< 10; i ++){

printf(" a test\ n);

}

返回0;

}

我得到....


[cdalten @localhost~] $ ./out

a测试

a测试

a测试

a测试

a测试


正如你所看到的那样打印出来的前几行。


无论如何,我可以确定这个输出缓冲区的大小没有

重新试用到试验和错误猜测有多大输出缓冲区

可能是?


Chad

解决方案

< blockquote> ./ out

a

a

a

a

a

a

a

a

a

a


但是现在,我将printf()更改为

printf(a test\ n);


现在我运行时

#include< stdio.h>


int main(无效){

int i = 0;


为(i = 0; I< 10; i ++){

printf(" a test\ nn);

}

返回0;

}

我得到....


[cdalten @ localhost~]


./ out

a测试

a测试

a测试

a测试

a测试

正如你所看到的,只有前几行被打印出来。


无论如何我可以确定这个输出缓冲区的大小没有

重新进行试验和错误以猜测输出缓冲区可能有多大?
可能是什么?


Chad


Chad写道:


好​​吧,让我们说我有一个异国情调的os限制了多少

stdout。我什么时候去...


#include< stdio.h>


int main(void){



这是交叉发布到comp.lang.c,我会保存clc人员

麻烦:它不是一个有效的C程序,如果main有错误的

参数数量。


可能是stdio有一个bug,但严格来说,如果你是

没有给系统一个有效的C程序,它没有必要有正确的输出




- Logan


Okay, let''s say I have an exotic os that limits how much goes to
stdout. When I go like..

#include <stdio.h>

int main(void) {
int i=0;

for(i=0; i< 10; i++) {
printf("a \n");
}
return 0;
}
I get this....
[cdalten@localhost ~]$ ./out
a
a
a
a
a
a
a
a
a
a

BUT Now, I change the printf() to
printf("a test\n");

Now when I run
#include <stdio.h>

int main(void) {
int i=0;

for(i=0; i< 10; i++) {
printf("a test\n");
}
return 0;
}
I get....

[cdalten@localhost ~]$ ./out
a test
a test
a test
a test
a test

As you can see, only the first few lines get printed out.

Is there anyway I can determine the size of this output buffer without
restorting to trial and error to guess how large the output buffer
might be?

Chad

解决方案

./out
a
a
a
a
a
a
a
a
a
a

BUT Now, I change the printf() to
printf("a test\n");

Now when I run
#include <stdio.h>

int main(void) {
int i=0;

for(i=0; i< 10; i++) {
printf("a test\n");
}
return 0;
}
I get....

[cdalten@localhost ~]


./out
a test
a test
a test
a test
a test

As you can see, only the first few lines get printed out.

Is there anyway I can determine the size of this output buffer without
restorting to trial and error to guess how large the output buffer
might be?

Chad


Chad wrote:

Okay, let''s say I have an exotic os that limits how much goes to
stdout. When I go like..

#include <stdio.h>

int main(void) {

This being cross-posted to comp.lang.c, I''ll save the c-l-c people
the trouble: it''s not a valid a C program if main has the wrong
number of arguments.

It could be that stdio has a bug, but strictly speaking, if you''re
not giving the system a valid C program, it doesn''t have to have
correct output.

- Logan


这篇关于如何确定输出缓冲区的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆