C functions for I/O
>>>>>NOT YET FINISHED<<<<<<
The following abbreviations are used:
fp = file pointer (a pointer to FILE structure)
fd = file descriptor (an integer)
format = a character string that contains format specifiers
arg = argument (could be an int, float, string, char or other type)
p_arg = pointer argument (a pointer or non-pointer variable name
preceded by &)
s = character string variable
buf = buffer, a character string
YOU SHOULD INCLUDE THE FOLLOWING INTO YOUR C SOURCE PROGRAMS:
#include
#include
-------------------High Level (formatted) I/O Routines-------------------------
fscanf (fp, format, p_arg1, p_arg2, ...) <-- input data from a file
scanf (format, p_arg1, p_arg2, ...) <-- input data from stdin
sscanf (s, format, p_arg1, p_arg2, ...) <-- input data from a string
fprintf (fp, format, arg1, arg2, ...) <-- print data to a file
printf (format, arg1, arg2, ...) <-- print data to stdout
sprintf (s, format, arg1, arg2) <-- print data to a string
-------------------------Low Level I/O Routines--------------------------------
atof (s) <-- convert ascii to float
atoi (s) <-- convert ascii to integer
atol (s) <-- convert ascii to long int
clearerr (fp) <-- clear errors of file "fp"
ecvt (val,ndigit,decpt,sign) <-- converts val into string of
ascii digits
float val; int ndigit; int *decpt,*sign;
fclose (fp, n) <-- flushes file buffer of file "fp"
if n=0, the LFN is freed.
fcvt (val,ndigit,decpt,sign) <-- same as ecvt except the correct
digit for FORTRAN F-format is
rounded.
fdopen (fd,rw_mode) <-- generates a file pointer for
a previously opened file des-
criptor "fd".
feof (fp) <-- determine if eof on file "fp"
been reached or not. Returns
0 if eof not yet reached.
ferror (fp) <-- returns non-zero if an error
occurred on file "fp".
fflush (fp) <-- flushes the file buffer for "fp"
fgetc (fp) <-- same as "getc" (which is a macro)
"fgetc" is not a macro.
fgets (buf,n,fp) <-- get a string from file "fp" until
newline is read or n-1 chars
have been read.
fileno (fp) <-- returns the fd for file "fp"
fopen (name,rw_mode,size,io_mode,open_mode)<-- opens a file. See C manual.
fopen_error () <-- prints the result of fopen().
Automatically called when fopen
fails.
fputc (c, fp) <-- Same as "putc" (which is a macro) "fputc" is not a macro.
fputs (s, fp) <-- writes the string s to file "fp"
fread (buf,size,n,fp) <-- reads up to n items from file
"fp" into buf. Each item is
"size" bytes long.
freopen (name,rw_mode,fp,io_mode) <-- closes the file "fp" and opens
the file named by "name."
fseek (fp,offset,origin) <-- positions the file "fp" for i/o.
ftell (fp) <-- returns current file position
of file "fp"
fwrite (buf,size,n,fp) <-- writes "n" items to file "fp"
from "buf". Each item is
"size" bytes long.
gcvt (val,ndigit,buf) <-- converts the float "val" to a
null-terminated ascii string
in "buf". "ndigit" significant
digits are produced.
getc (fp) <-- get next unread character from
file "fp".
--------------------------Very Low level I/O routines---------------------------
open (filename, flags) <-- open a file, return an fd
close (fd) <-- close a file
read (fd, buf, nbytes) <-- attempt to read nbytes from file
write (fd, buf, nbytes) <-- attempt to write nbytes to file