Im writing a small C program that should accept an input stream larger than 4096 bytes.
I found a post recommending using setvbuf () here:
Creating fgets for longer read () calls on Linux
It’s still very difficult for me to get this to work - this is some of my code that I am struggling with:
int main(void) { #define MAX_STRING_SIZE 7168 char input_string[MAX_STRING_SIZE]; printf( "Input: " ); setvbuf( stdin, NULL, _IONBF, 0 ); fgets( input_string, MAX_STRING_SIZE-1, stdin ); printf( "\n" ); printf( "%s", input_string ); }
Has anyone managed to increase this input buffer?
My environment: Ubuntu 10.10 with build-essential
Thank!
_IONBF, . _IOFBF , , ( ). , , :
_IONBF
_IOFBF
setvbuf(stdin, NULL, _IOFBF, 16384);
. :
char mybuffer[32768]; setvbuf(stdin, mybuffer, _IOFBF, sizeof(mybuffer));
. - , fgets (, , fgetc fscanf), , read syscalls , 1 . , , ( fread), , , . , setvbuf , , , , -.
fgets
fgetc
fscanf
read
fread
setvbuf