Download Pelles C here: http://www.pellesc.se
#include <stdio.h>
int main(void)
{
int size = 0;
if (setvbuf(stdout, NULL, _IOFBF, 5000))
fprintf(stdout, "setvbuf error\n");
else {
for (int i = 0; i <= 309; i++)
size += fprintf(stdout, "'%d'\n", i);
fprintf(stdout, "size: %d\n", size);
}
return 0;
}
'307'
'08'
'309'
size: 1750#include <stdio.h>
int main(void)
{ // all problems go away when next line is added
printf("test result");// initializes stdout I/O ?
setvbuf(stdout, NULL, _IOFBF, 7003);
for (int i = 0; i <= 1351; i++)
printf("%d?\n", i);
return 0;
}#include <stdio.h>
int main(void)
{
setvbuf(stdout, NULL, _IOFBF, 7000);
for (int i = 0; i <= 1351; i++)
printf("%d?\n", i);
return 0;
}
output:...
1328?
329?
1330?
1331?
1332?
1333?
1334?
1335?
1336?
1337?
1338?
1339?
1340?
1341?
1342?
1343?
1344?
1345?
1346?
1347?
1348?
1349?
1350?
13511351?'1157'
'1151158'
'1159'size: 7003Quote from: TimoVJL on March 09, 2026, 11:54:49 AMhttps://en.cppreference.com/w/c/io/setvbufI have read it last week. "the actual buffer size is usually rounded down to a multiple of 2". Just NOT use some bytes, so any number is OK.
buffer size should be at least multiple of 2
Quote from: John Z on March 09, 2026, 09:56:30 AMHi ander,thank you for test.
I could not reproduce this. With the setvbuf 1000, 5000, 7000, or not even use setvbuf it always ends the loop on 20000 . I just pasted your code in.19998
19999
20000
Press any key to continue...
John Z
Page created in 0.067 seconds with 18 queries.