[Previous]
[Contents]
[Next]

input_line()

get a string of characters from a file

Synopsis:

#include <stdio.h>
char *input_line( FILE *fp, 
                  char *buf, 
                  int bufsize );

extern int _input_line_max;

Description:

The input_line() function gets a string of characters from the file designated by fp and stores them in the array pointed to by buf. The input_line() function stops reading characters when:

In addition the input_line() function buffers the last _input_line_max lines internally. The _input_line_max variable is defined in <stdio.h>. It can be set before the first invocation of input_line(), and has a default value of 20. While the line is being input the KEY_UP and KEY_DOWN keys can be used to move to the previous and next line respectively in a circular buffer of previously read lines. The newline character (\n) is replaced with the NULL character on input.

Returns:

A pointer to the input line. On end-of-file or on encountering an error reading from fp, NULL is returned and errno is set.

Examples:

#include <stdio.h>

#define SIZ 256

int _input_line_max;

void main()
  {
    FILE    *fp;
    char    *p,
         buf[SIZ];

    fp = stdin;               /* Or any stream */
    _input_line_max = 25;     /*  set before 1st call */

    while( ( p = input_line( fp, buf, SIZ ) ) != NULL ) {
      printf( "%s\n", buf );
      fflush( stdout );
    }
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

dev_insert_chars()


[Previous]
[Contents]
[Next]