Document revision date: 15 July 2002 | |
Previous | Contents | Index |
Perform a printf in the specified window, starting at the current position of the cursor. The printw function acts on the stdscr window.
#include <curses.h>printw (char *format_spec, ...);
int wprintw (WINDOW *win, char *format_spec, ...);
win
A pointer to the window.format_spec
A pointer to the format specification string....
Optional expressions whose resultant types correspond to conversion specifications given in the format specification.If no conversion specifications are given, you may omit the output sources. Otherwise, the function call must have exactly as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources.
Conversion specifications are matched to output sources in left-to-right order. Excess output pointers, if any, are ignored.
The formatting specification (format_spec) and the other arguments are identical to those used with the printf function.The printw and wprintw functions format and then print the resultant string to the window using the addstr function. For more information, see the printf and scrollok functions in this section. See Chapter 2 for information on format specifiers.
OK Indicates success. ERR Indicates that the function makes the window scroll illegally.
The putc macro writes a single character to a specified file.
#include <stdio.h>int putc (int character, FILE *file_ptr);
character
An object of type int .file_ptr
A file pointer.
Since putc is a macro, a file pointer argument with side effects (for example, putc (ch, *f++) ) might be evaluated incorrectly. In such a case, use the fputc function instead. See also fputc in this section.
x The character written to the file. Indicates success. EOF Indicates output errors.
Writes a single character to the standard output ( stdout ) and returns the character.
#include <stdio.h>int putchar (int character);
character
An object of type int .
The putchar function is identical to fputc (character, stdout ).
character Indicates success. EOF Indicates output errors.
Sets an environmental variable.
#include <stdlib.h>int putenv (const char *string);
string
A pointer to a name=value string.
The putenv function sets the value of an environment variable by altering an existing variable or by creating a new one. The string argument points to a string of the form name=value, where name is the environment variable and value is the new value for it.The string pointed to by string becomes part of the environment, so altering the string changes the environment. When a new string-defining name is passed to putenv , the space used by string is no longer used.
0 Indicates success. - 1 Indicates an error. errno is set to ENOMEM---Not enough memory available to expand the environment list.
The putenv function cannot take a 64-bit address. See Section 1.10.
Writes a character string to the standard output ( stdout ) followed by a new-line character.
#include <stdio.h>int puts (const char *str);
str
A pointer to a character string.
The puts function does not copy the terminating null character to the output stream.
Nonnegative value Indicates success. EOF Indicates output errors.
Writes characters to a specified file.
#include <stdio.h>int putw (int integer, FILE *file_ptr);
integer
An object of type int or long .file_ptr
A file pointer.
The putw function writes four characters to the output file as an int . No conversion is performed.
integer Indicates success. EOF Indicates output errors.
Converts a wide character to its corresponding multibyte value, and writes the result to a specified file.
#include <wchar.h>wint_t putwc (wint_t wc, FILE *file_ptr);
wc
An object of type wint_t .file_ptr
A file pointer.
Since putwc might be implemented as a macro, a file pointer argument with side effects (for example putwc (wc, *f++) ) might be evaluated incorrectly. In such a case, use the fputwc function instead.See also fputwc in this section.
x The character written to the file. Indicates success. WEOF Indicates an output error. The function sets errno . For a list of the errno values set by this function, see fputwc in this section.
Writes a wide character to the standard output ( stdout ) and returns the character.
#include <wchar.h>wint_t putwchar (wint_t wc);
wc
An object of type wint_t .
The putwchar function is identical to fputwc (wc, stdout ).
x The character written to the file. Indicates success. WEOF Indicates an output error. The function sets errno . For a list of the errno values set by this function, see fputwc in this section.
Returns the absolute value of an integer as an __int64 . llabs is a synonym for qabs .
#include <stdlib.h>__int64 qabs (__int64 j);
__int64 llabs (__int64 j);
j
A value of type __int64 .
Returns the quotient and the remainder after the division of its arguments. lldiv is a synonym for qdiv .
#include <stdlib.h>qdiv_t qdiv (__int64 numer, __int64 denom);
lldiv_t lldiv (__int64 numer, __int64 denom);
numer
A numerator of type __int64 .denom
A denominator of type __int64 .
The types qdiv_t and lldiv_t are defined in the <stdlib.h> header file as follows:
typedef struct { __int64 quot, rem; } qdiv_t, lldiv_t;
Sorts an array of objects in place. It implements the quick-sort algorithm.
#include <stdlib.h>Function Variants The qsort function has variants named _qsort32 and _qsort64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions.void qsort (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *));
base
A pointer to the first member of the array. The pointer should be of type pointer-to-element and cast to type pointer-to-character.nmemb
The number of objects in the array.size
The size of an object, in bytes.compar
A pointer to the comparison function.
Two arguments are passed to the comparison function pointed to by compar. The two arguments point to the objects being compared. Depending on whether the first argument is less than, equal to, or greater than the second argument, the comparison function returns an integer less then, equal to, or greater than 0.The comparison function compar need not compare every byte, so arbitrary data might be contained in the objects in addition to the values being compared.
The order in the output of two objects that compare as equal is unpredictable.
Generates a specified software signal. Generating a signal causes the action routine established by the signal , ssignal , or sigvec function to be invoked.
#include <signal.h>int raise (int sig); (ANSI C)
int raise (int sig[, int sigcode]); (COMPAQ C EXTENSION)
sig
The signal to be generated.sigcode
An optional signal code, available only when not compiling in strict ANSI C mode. For example, signal SIGFPE---the arithmetic trap signal---has 10 different codes, each representing a different type of arithmetic trap.The signal codes can be represented by mnemonics or numbers. The arithmetic trap codes are represented by the numbers 1 to 10; the SIGILL codes are represented by the numbers 0 to 2. The code values are defined in the <signal.h> header file. See Tables 4-4 and 4-5 for a list of signal mnemonics, codes, and corresponding OpenVMS exceptions.
Calling the raise function has one of the following results:
- If raise specifies a sig argument that is outside the range defined in the <signal.h> header file, then the raise function returns 0, and the errno variable is set to EINVAL.
- If signal , ssignal , or sigvec establishes SIG_DFL (default action) for the signal, then the functions do not return. The image is exited with the OpenVMS error code corresponding to the signal.
- If signal , ssignal , or sigvec establishes SIG_IGN (ignore signal) as the action for the signal, then raise returns its argument, sig.
- signal , ssignal , or sigvec must establish an action function for the signal. That function is called and its return value is returned by raise .
See Chapter 4 for more information on signal processing.
See also gsignal , signal , ssignal , and sigvec in this section.
0 If successful. nonzero If unsuccessful.
Returns pseudorandom numbers in the range 0 to 231 - 1.
#include <math.h>int rand (void);
The rand function uses the following ANSI Standard algorithm to return a random number:
static unsigned int next = 1; int rand(void) { next = next * 1103515245 + 12345; return (next & RAND_MAX); }See also srand in this section.
For other random-number algorithms, see random and all the * 48 functions.
Generates pseudorandom numbers in a more random sequence.
#include <stdlib.h>long int random (void);
The random function is a random-number generator that has virtually the same calling sequence and initialization properties as the rand function, but produces sequences that are more random. The low 12 bits generated by rand go through a cyclic pattern. All bits generated by random are usable. For example, random () &1 produces a random binary value.The random function uses a nonlinear, additive-feedback, random-number generator employing a default state-array size of 31 integers to return successive pseudorandom numbers in the range from 0 to 231-1 . The period of this random-number generator is approximately 16*( 231-1 ). The size of the state array determines the period of the random-number generator. Increasing the state array size increases the period.
With a full 256 bytes of state information, the period of the random-number generator is greater than 269 , and is sufficient for most purposes.
Like the rand function, the random function produces by default a sequence of numbers that you can duplicate by calling the srandom function with a value of 1 as the seed. The srandom function, unlike the srand function, does not return the old seed because the amount of state information used is more than a single word.
See also rand , srand , srandom , setstate , and initstate in this section.
n A random number.
Raw mode only works with the Curses input routines [w]getch and [w]getstr . Raw mode is not supported with the Compaq C RTL emulation of UNIX I/O, Terminal I/O, or Standard I/O.
#include <curses.h>raw()
noraw()
Raw mode reads are satisfied on one of two conditions: after a minimum number (5) of characters are input at the terminal or after waiting a fixed time (10 seconds) from receipt of any characters from the terminal.
/* Example of standard and raw input in Curses package. */ #include <curses.h> main() { WINDOW *win1; char vert = '.', hor = '.', str[80]; /* Initialize standard screen, turn echo off. */ initscr(); noecho(); /* Define a user window. */ win1 = newwin(22, 78, 1, 1); leaveok(win1, TRUE); leaveok(stdscr, TRUE); box(stdscr, vert, hor); /* Reset the video, refresh(redraw) both windows. */ mvwaddstr(win1, 2, 2, "Test line terminated input"); wrefresh(win1); /* Do some input and output it. */ nocrmode(); wgetstr(win1, str); mvwaddstr(win1, 5, 5, str); mvwaddstr(win1, 7, 7, "Type something to clear screen"); wrefresh(win1); /* Get another character then delete the window. */ wgetch(win1); wclear(win1); mvwaddstr(win1, 2, 2, "Test raw input"); wrefresh(win1); /* Do some raw input 5 chars or timeout - and output it. */ raw(); getstr(str); noraw(); mvwaddstr(win1, 5, 5, str); mvwaddstr(win1, 7, 7, "Raw input completed"); wrefresh(win1); endwin(); }
Reads bytes from a file and places them in a buffer.
#include <unistd.h>ssize_t read (int file_desc, void *buffer, size_t nbytes); (ISO POSIX-1)
int read (int file_desc, void *buffer, int nbytes); (COMPATABILITY)
file_desc
A file descriptor. The specified file descriptor must refer to a file currently opened for reading.buffer
The address of contiguous storage in which the input data is placed.nbytes
The maximum number of bytes involved in the read operation.
The read function returns the number of bytes read. The return value does not necessarily equal nbytes. For example, if the input is from a terminal, at most one line of characters is read.
Note
The read function does not span record boundaries in a record file and, therefore, reads at most one record. A separate read must be done for each record.
n The number of bytes read. - 1 Indicates a read error, including physical input errors, illegal buffer addresses, protection violations, undefined file descriptors, and so forth.
#include <file.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> main() { int fd, i; char buf[10]; FILE *fp ; /* Temporary STDIO file */ /* Create a dummy data file */ if ((fp = fopen("test.txt", "w+")) == NULL) { perror("open"); exit(1); } fputs("XYZ\n",fp) ; fclose(fp) ; /* And now practice "read" */ if ((fd = open("test.txt", O_RDWR, 0, "shr=upd")) <= 0) { perror("open"); exit(0); } /* Read 2 characters into buf. */ if ((i = read(fd, buf, 2)) < 0) { perror("read"); exit(0); } /* Print out what was read. */ if (i > 0) printf("buf='%c%c'\n", buf[0], buf[1]); close(fd); }
Previous | Next | Contents | Index |
privacy and legal statement | ||
5763PRO_044.HTML |