simpio.h

This interface exports several functions that simplify the reading of input data.
Functions
getInteger() Reads a line of text from standard input and scans it as an integer.
getLong() Reads a line of text from standard input and scans it as a long.
getReal() Reads a line of text from standard input and scans it as a double.
getLine() Reads a line of text from standard input and returns the line as a string.
readLine(infile) Reads a line of text from the input file and returns the line as a string.
readLinesFromStream(infile) Reads an entire file into a NULL-terminated array of lines.
readLinesFromFile(filename) Reads an entire file into a NULL-terminated array of lines.

Function detail


int getInteger(void);
Reads a line of text from standard input and scans it as an integer. If an integer cannot be scanned or if extraneous characters follow the number, the user is given a chance to retry.

Usage:

n = getInteger();

long getLong(void);
Reads a line of text from standard input and scans it as a long. If an integer cannot be scanned or if extraneous characters follow the number, the user is given a chance to retry.

Usage:

l = getLong();

double getReal(void);
Reads a line of text from standard input and scans it as a double. If an number cannot be scanned or if extraneous characters follow the number, the user is given a chance to retry.

Usage:

d = getReal();

string getLine(void);
Reads a line of text from standard input and returns the line as a string. The newline character that terminates the input is not stored as part of the result.

Usage:

s = getLine();

string readLine(FILE *infile);
Reads a line of text from the input file and returns the line as a string. The newline character that terminates the input is not stored as part of the result. The readLine function returns NULL if infile is at the end-of-file position.

Usage:

s = readLine(infile);

string *readLinesFromStream(FILE *infile);
Reads an entire file into a NULL-terminated array of lines. Opening and closing the file stream is the responsibility of the caller.

Usage:

string *array = readLinesFromStream(infile);

string *readLinesFromFile(string filename);
Reads an entire file into a NULL-terminated array of lines. This version opens the file, reads it, and closes it at the end. If the file name is "-", the function reads from stdin.

Usage:

string *array = readLinesFromFile(filename);