 |
getsn |
Function* (tigcc.a) |
Gets a string from the keyboard avoiding buffer overflows.
getsn works like gets, but with a maximum length specified.
The maximum length (maxlen
) is the total size of the buffer. In other words, the
null-terminator is included in the maximum length. When the buffer is full (i.e. when the
string length is maxlen - 1
), getsn will not accept any more characters.
Only backspace or ENTER are allowed in that situation.
Here is an example of usage:
char buffer[50];
int a, b;
clrscr ();
puts ("A = ");
a = atoi (getsn (buffer, 50));
puts ("B = ");
b = atoi (getsn (buffer, 50));
printf ("%d + %d = %d", a, b, a+b);
atoi is an ANSI C standard function from stdlib.h
header file.
Note: getsn is not an ANSI C standard function, but the equivalent of
fgets (buffer, maxlen, stdin)
in ANSI C. It is needed because terminal streams are not
implemented in TIGCCLIB.
Uses: fputchar, printf, EV_captureEvents, EV_defaultHandler, MoveTo, SaveScrState, ngetchx
Used by: scanf, vscanf
See also: gets, fgets, How can I get input from the keyboard?, textedit.h