Programming in C

(Barry) #1
478 Appendix B The Standard C Library

int puts (buffer)
Writes the characters contained in bufferto stdoutuntil a null character is encoun-
tered. A newline character is automatically written as the last character (unlike the
fputsfunction). On error,EOFis returned.
int remove (fileName)
Removes the specified file. A nonzero value is returned on failure.
int rename (fileName1, fileName2)
Renames the file fileName1to fileName2,returning a nonzero result on failure.
void rewind (filePtr)
Resets the indicated file back to the beginning.
int scanf (format, arg1, arg2, ..., argn)
Reads items from stdinaccording to the format specified by the string format(see
Chapter 16).The arguments that follow formatmust all be pointers.The number of
items successfully read and assigned (excluding %nassignments) is returned by the
function.The value EOFis returned if an end of file is encountered before any items
have been converted.
FILE *tmpfile (void)
Creates and opens a temporary binary file in write update mode ("r+b"); it returns
NULLif an error occurs.The temporary file is automatically removed when the pro-
gram terminates. (A function called tmpnamis also available for creating unique, tem-
porary file names.)
int ungetc (c, filePtr)
Effectively “puts back” a character to the indicated file.The character is not actually
written to the file but is placed in a buffer associated with the file.The next call to
getcreturns this character.The ungetcfunction can only be called to “put back” one
character to a file at a time; that is, a read operation must be performed on the file
before another call to ungetccan be made.The function returns cif the character is
successfully “put back”; otherwise, it returns the value EOF.

In-Memory Format Conversion Functions


The functions sprintfand sscanfare provided for performing data conversion in
memory.These functions are analogous to the fprintfand fscanffunctions, except a
character string replaces the FILEpointer as the first argument.You should include the
header file <stdio.h>in your program when using these routines.

21 0672326663 AppB 6/10/04 2:03 PM Page 478

Free download pdf