Table of Contents

NAME

QccFileReadChar, QccFileWriteChar, QccFileReadInt, QccFileWriteInt, QccFileReadDouble, QccFileWriteDouble, QccFileReadString, QccFileWriteString, QccFileReadLine, QccFileSkipWhiteSpace - reading and writing of files

SYNOPSIS

#include "libQccPack.h"

int QccFileReadChar(FILE *infile, char *val);
int QccFileWriteChar(FILE *outfile, char val);
int QccFileReadInt(FILE *infile, int *val);
int QccFileWriteInt(FILE *outfile, int val);
int QccFileReadDouble(FILE *infile, double *val);
int QccFileWriteDouble(FILE *outfile, double val);
int QccFileReadString(FILE *infile, QccString s);
int QccFileWriteString(FILE *outfile, const QccString s);
int QccFileReadLine(FILE *infile, QccString s);
int QccFileSkipWhiteSpace(FILE *infile, int skip_comments_flag);

DESCRIPTION

The following routines read and write binary data to files:
QccFileReadChar()
reads a char into the location pointed to by val.
QccFileWriteChar()
writes the char in val.
QccFileReadInt()
reads an int into the location pointed to by val.
QccFileWriteInt()
writes the int in val.
QccFileReadDouble()
reads a double into the location pointed to by val.
QccFileWriteDouble()
writes the double in val.

In reading and writing int and double values, the routines QccBinaryCharToInt(3) , QccBinaryIntToChar(3) , QccBinaryCharToFloat(3) , and QccBinaryFloatToChar(3) are used to ensure that the binary values are read/written from files in MSB-first order despite the byte ordering native to the machine. Thus, files produced by QccPack should be portable across different architectures. QccPack stores floating-point numbers in its files using 4 bytes (32-bit precision); hence QccFileWriteDouble() actually casts the double value to a float before writing and can therefore incur some precision loss. In each of the read routines, storage space pointed to by val must be allocated in the appropriate amount prior to calling the routine.

QccFileReadString() reads a QccString into s, which must be allocated prior to calling QccFileReadString(). The string is truncated to QCCSTRINGLEN characters to avoid overrunning s.

QccFileWriteString() writes a QccString.

QccFileReadLine() reads an entire line from infile, up to and including the newline character. The characters of the line, except for the newline character, are returned in the string s, with the line being truncated to QCCSTRINGLEN characters to avoid overrunning s.

QccFileSkipWhiteSpace() skips over white space and, if skip_comments_flag is nonzero, comment lines, in the input file. White space includes space, `\n' (newline), `\t' (tab), and `\r' (return) characters. A comment line is any line that starts with a `#', `*', or `/'. When QccFileSkipWhiteSpace() returns, the file is positioned to the next non-white-space character not on a comment line.

RETURN VALUE

Each of these routines return 0 upon successful completion. If an error occurs while accessing the file, 1 is returned.

SEE ALSO

QccFileOpen(3) , QccBinaryCharToInt(3) , QccBinaryIntToChar(3) , QccBinaryCharToFloat(3) , QccBinaryFloatToChar(3) , QccPack(3)

AUTHOR

Copyright (C) 1997-2021 James E. Fowler


Table of Contents



Get QccPack at SourceForge.net. Fast, secure and Free Open Source software downloads