www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/30/05:07:43

Date: Sun, 30 Jul 2000 11:02:38 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: "Paulo J. Matos aka PDestroy" <pdestroy AT netcabo DOT pt>
cc: djgpp AT delorie DOT com
Subject: Re: fgets Max Chars
In-Reply-To: <8luvll$tj6$1@duke.telepac.pt>
Message-ID: <Pine.SUN.3.91.1000730105642.23058B-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sat, 29 Jul 2000, Paulo J. Matos aka PDestroy wrote:

> #include <stdio.h>
> 
> int main(void) {
>     char *s;
> 
>     s=malloc(3000);
> 
>     fgets(s, 3000, stdin);
>     return 1;
> }
> 
> Althought I malloced 3000 chars I am only able to write 129...

Modify your program like shown below, and it will do what you expect.

(Although generally a good idea, tcflush is not really needed in the
particular case of this simple test program.  I used it because it
causes termios to kick in and handle console input, instead of DOS.
This works around the limitations of the DOS console device driver.)

 #include <stdio.h>
 #include <stdlib.h>
 #include <termios.h>
 
 int main(void) {
     char *s;
 
     s=malloc(3000);
 
     tcflush(fileno(stdin), TCIFLUSH);
     fgets(s, 3000, stdin);
     return 1;
 }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019