473,715 Members | 5,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine the size of an output buffer

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@localho st ~]$ ./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@localho st ~]$ ./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

Apr 13 '07 #1
19 2639
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
Apr 13 '07 #2
Logan Shaw <lshaw-use...@austin.r r.comwrote:
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.
Since clc wouldn't have said that about the OP's code, I'm not sure
what trouble you're saving clc from. The signature for main is not
only valid, but any conforming hosted implementation must support it.

Perhaps you were thinking of void main(void)?

--
Peter

Apr 13 '07 #3
On Apr 13, 11:43 am, "Chad" <cdal...@gmail. comwrote:
Okay, let's say I have an exotic os that limits how much goes to
stdout.
Many systems allow stdout to be redirected, and many systems allow
user file limits. So, such a system isn't as exotic as you might
think.
When I go like..

#include <stdio.h>

int main(void) {
int i=0;

for(i=0; i< 10; i++) {
printf("a \n");
Note that implementations are allowed to strip trailing whitespace
from text stream lines. [In other words, behave as if you had
written printf("a\n");]
}
return 0;

}

I get this....
[cdalten@localho st ~]$ ./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
<snip>
I get....

[cdalten@localho st ~]$ ./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?
No, but you can always check the return value of printf for
error (or ferror) as you can with other output functions.

--
Peter

Apr 13 '07 #4
On Apr 12, 7:02 pm, "Peter Nilsson" <a...@acay.com. auwrote:
Logan Shaw <lshaw-use...@austin.r r.comwrote:
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.

Since clc wouldn't have said that about the OP's code, I'm not sure
what trouble you're saving clc from. The signature for main is not
only valid, but any conforming hosted implementation must support it.

Perhaps you were thinking of void main(void)?

--
Trying not to get to far off topic, here is what happens when I change
int main(void)

to

void main(void)

[cdalten@localho st ~]$ gcc --version
gcc (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

[cdalten@localho st ~]$ gcc -Wall out.c -o out
out.c:3: warning: return type of 'main' is not 'int'
out.c: In function 'main':
out.c:9: warning: 'return' with a value, in function returning void


Apr 13 '07 #5
In article <46************ ***********@roa drunner.com>,
Logan Shaw <ls**********@a ustin.rr.comwro te:
>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.
Uhh... what? That's a perfectly valid set of arguments for main();
one of the two that are specifically described as acceptable, in fact.

>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.
I don't seem to recall the OP claiming that the described behavior was
observed anywhere; he was asking about how to determine the details
given an implementation that *did* act that way.
dave
(stdio output functions are supposed to report failure, aren't they?
Don't forget to flush.)

--
Dave Vandervies dj******@csclub .uwaterloo.ca
If you write out a fully-factored grammar, this problem never occurs. [The
problem that occurs instead is that you go crazy and start mumbling thousands
of sub-rules.]) --Chris Torek in comp.lang.c
Apr 13 '07 #6
On 12 Apr 2007 19:09:11 -0700, "Chad" <cd*****@gmail. comwrote in
comp.lang.c:
On Apr 12, 7:02 pm, "Peter Nilsson" <a...@acay.com. auwrote:
Logan Shaw <lshaw-use...@austin.r r.comwrote:
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.
Since clc wouldn't have said that about the OP's code, I'm not sure
what trouble you're saving clc from. The signature for main is not
only valid, but any conforming hosted implementation must support it.

Perhaps you were thinking of void main(void)?

--

Trying not to get to far off topic, here is what happens when I change
int main(void)

to

void main(void)

[cdalten@localho st ~]$ gcc --version
gcc (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

[cdalten@localho st ~]$ gcc -Wall out.c -o out
out.c:3: warning: return type of 'main' is not 'int'
out.c: In function 'main':
out.c:9: warning: 'return' with a value, in function returning void
No, don't do that. Logan Shaw either had a brain fart or he doesn't
know as much about C as he thinks he does.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Apr 13 '07 #7
On Apr 13, 12:09 pm, "Chad" <cdal...@gmail. comwrote:
On Apr 12, 7:02 pm, "Peter Nilsson" <a...@acay.com. auwrote:
Logan Shaw <lshaw-use...@austin.r r.comwrote:
Chad wrote:
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.
Since clc wouldn't have said that about the OP's code, I'm not
sure what trouble you're saving clc from. The signature for main
is not only valid, but any conforming hosted implementation must
support it.

Perhaps you were thinking of void main(void)?

Trying not to get to far off topic, here is what happens when I
change int main(void) to void main(void)...
What happens is that you go from having a program with behaviour
defined by the C language standards, to a program with behaviour
that isn't.

http://c-faq.com/ansi/voidmain.html

--
Peter

Apr 13 '07 #8
Peter Nilsson wrote:
Logan Shaw <lshaw-use...@austin.r r.comwrote:
>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.
Since clc wouldn't have said that about the OP's code, I'm not sure
what trouble you're saving clc from. The signature for main is not
only valid, but any conforming hosted implementation must support it.
Well, that is embarrassing.

I could've sworn that I was told by somebody at one point that only
the other form was valid. Or maybe I misunderstood someone's statement
at some point in the past.

At any rate, I regret spreading wrong information.

On the other hand, I am glad to have found out the real story, because
I have often found it irritating thinking I had to declare arguments
when actually there was a perfectly legal alternative...

- Logan
Apr 13 '07 #9
Logan Shaw wrote:
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.
That's true, but
int main(void) {
has the right number of arguments, being one of the two forms that a
compiler is _required_ to handle properly.
What was your point?
Apr 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
10662
by: Walter L. Preuninger II | last post by:
I would like to write a generic procedure that will take string or numeric variables. I can not think of a way to make this more clear except to show what I want. int main(void) { int i=7; char *s="/etc/filesystems"; generic(i);
11
3607
by: Sontu | last post by:
Consider the following code: int main(void) { char buffer; func(buffer); } void func(char *bufpas) {
7
5636
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store strings of any lengths into an array of pointers to char type variable. my problem is: given the declaration
0
1060
by: Terry Olsen | last post by:
Using #ZipLib, I'm zipping up large files (100MB & >). I'm using a byte array to read in the file and write out to the zip file. The bigger the chunks I can read in the faster the zipping goes. What's the best way to determine how big I can make the byte array? I'm guessing that I would determine the amount of available memory and take a percentage of that? OR: does anyone have any code using #ZipLib that demonstrates how to zip...
6
5784
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line of entry in EOF while loop ? while (! file.eof() ) { ....
5
6317
by: Paul | last post by:
hi, there, I was asked such a question: how to determine the size of memory of the int pointer pointed? for example int GetTheSizeofMemory(int *buffer) { int size; //enter your code here, to calculate the memory size of buffer
158
6121
by: jty0734 | last post by:
i don't know what input size of string is. so i can't gets inputsize before malloc function. i want determine the size of malloc without get inputsize in advance. how to deal with it?
36
3803
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used to read text or handle arrays of arbitrary length. I don't have the expertise in C of many folks here so I feel like I'm offering a small furry animal for sacrifice to a big armour plated one... but will offer it anyway. Please do suggest...
3
13246
by: Giampaolo Rodola' | last post by:
Hi, I'd like to know if there's a way to determine which is the best buffer size to use when you have to send() and recv() some data over the network. I have an FTP server application which, on data channel, uses 8192 bytes as buffer for both incoming and outgoing data. Some time ago I received a report from a guy who stated that changing the buffers from 8192 to 4096 results in a drastical speed improvement. I tried to make some tests...
0
9343
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9198
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.