[an error occurred while processing this directive]
HP OpenVMS SystemsC Programming Language |
Compaq C
|
Previous | Contents | Index |
Changes a string such that the changed string can be passed to the strcmp function and produce the same result as passing the unchanged string to the strcoll function.
#include <string.h>size_t strxfrm (char *s1, const char *s2, size_t maxchar);
s1, s2
Pointers to character strings.maxchar
The maximum number of bytes (including the null terminator) to be stored in s1.
This function transforms the string pointed to by s2 , and stores the resulting string in the array pointed to by s1 . No more than maxchar bytes, including the null terminator, are placed into the array pointed to by s1 .If the value of maxchar is less than the required size to store the transformed string (including the terminating null), the contents of the array pointed to by s1 is indeterminate. In such a case, the function returns the size of the transformed string.
If maxchar is 0, then s1 is allowed to be a NULL pointer, and the function returns the required size of the s1 array before making the transformation.
The string comparison functions, strcoll and strcmp , can produce different results given the same two string to compare. The reason for this is that strcmp does a straightforward comparison of the code point values of the characters in the strings, whereas strcoll uses the locale information to do the comparison. Depending on the locale, the strcoll comparison can be a multipass operation, which is slower than strcmp .
The purpose of the strxfrm function is to transform strings in such a way that if you pass two transformed strings to the strcmp function, the result is the same as passing the two original strings to the strcoll function. The strxfrm function is useful in applications that need to do a large number of comparisons on the same strings using strcoll . In this case, it might be more efficient (depending on the locale) to transform the strings once using strxfrm , and then do comparisons using strcmp .
x Length of the resulting string pointed to by s1, not including the terminating null character. No return value is reserved for error indication. However, the function can set errno to EINVAL -- The string pointed to by ws2 contains characters outside the domain of the collating sequence.
/* This program verifies that two transformed strings when */ /* passed through strxfrm and then compared, provide the same */ /* result as if passed through strcoll without any */ /* transformation. #include <string.h> #include <stdio.h> #include <stdlib.h> #include <locale.h> #define BUFF_SIZE 256 main() { char string1[BUFF_SIZE]; char string2[BUFF_SIZE]; int errno; int coll_result; int strcmp_result; size_t strxfrm_result1; size_t strxfrm_result2; /* setlocale to French locale */ if (setlocale(LC_ALL, "fr_FR.ISO8859-1") == NULL) { perror("setlocale"); exit(EXIT_FAILURE); } /* collate string 1 and string 2 and store the result */ errno = 0; coll_result = strcoll("<a`>bcd", "abcz"); if (errno) { perror("strcoll"); exit(EXIT_FAILURE); } else { /* Transform the strings (using strxfrm) into string1 */ /* and string2 */ strxfrm_result1 = strxfrm(string1, "<a`>bcd", BUFF_SIZE); if (strxfrm_result1 == ((size_t) - 1)) { perror("strxfrm"); exit(EXIT_FAILURE); } else if (strxfrm_result1 > BUFF_SIZE) { perror("\n** String is too long **\n"); exit(EXIT_FAILURE); } else { strxfrm_result2 = strxfrm(string2, "abcz", BUFF_SIZE); if (strxfrm_result2 == ((size_t) - 1)) { perror("strxfrm"); exit(EXIT_FAILURE); } else if (strxfrm_result2 > BUFF_SIZE) { perror("\n** String is too long **\n"); exit(EXIT_FAILURE); } /* Compare the two transformed strings and verify */ /* that the result is the same as the result from */ /* strcoll on the original strings */ else { strcmp_result = strcmp(string1, string2); if (strcmp_result == 0 && (coll_result == 0)) { printf("\nReturn value from strcoll() and " "return value from strcmp() are both zero."); printf("\nThe program was successful\n\n"); } else if ((strcmp_result < 0) && (coll_result < 0)) { printf("\nReturn value from strcoll() and " "return value from strcmp() are less than zero."); printf("\nThe program successful\n\n"); } else if ((strcmp_result > 0) && (coll_result > 0)) { printf("\nReturn value from strcoll() and return " " value from strcmp() are greater than zero."); printf("\nThe program was successful\n\n"); } else { printf("** Error **\n"); printf("\nReturn values are not of the same type"); } } } } }
Running the example program produces the following result:
Return value from strcoll() and return value from strcmp() are less than zero. The program was successful |
Creates a new subwindow with numlines lines and numcols columns starting at the coordinates (begin_y,begin_x) on the terminal screen.
#include <curses.h>WINDOW *subwin (WINDOW *win, int numlines, int numcols, int begin_y, int begin_x);
win
A pointer to the parent window.numlines
The number of lines in the subwindow. If numlines is 0, then the function sets that dimension to LINES -- begin_y. To get a subwindow of dimensions LINES by COLS, use the following format:
subwin (win, 0, 0, 0, 0)numcols
The number of columns in the subwindow. If numcols is 0, then the function sets that dimension to COLS -- begin_x. To get a subwindow of dimensions LINES by COLS, use the following format:
subwin (win, 0, 0, 0, 0)begin_y
A window coordinate at which the subwindow is to be created.begin_x
A window coordinate at which the subwindow is to be created.
When creating the subwindow, begin_y and begin_x are relative to the entire terminal screen. If either numlines or numcols is 0, then the subwin function sets that dimension to (LINES -- begin_y) or (COLS -- begin_x), respectively.The window pointed to by win must be large enough to contain the entire area of the subwindow. Any changes made to either window within the coordinates of the subwindow appear on both windows.
window pointer A pointer to an instance of the structure window corresponding to the newly created subwindow. ERR Indicates an error.
Swaps bytes.
#include <unistd.h>void swab (const void *src, void *dest, ssize_t nbytes);
src
A pointer to the location of the string to copy.dest
A pointer to where you want the results copied.nbytes
The number of bytes to copy. Make this argument an even value. When it is an odd value, the swab function uses nbytes --1 instead.
This function copies the number of bytes specified by nbytes from the location pointed to by src to the array pointed to by dest. The function then exchanges adjacent bytes. If a copy takes place between objects that overlap, the result is undefined.
Writes output to an array of wide characters under control of the wide-character format string.
#include <wchar.h>int swprintf (wchar_t *s, size_t n, const wchar_t *format, ...);
s
A pointer to the resulting wide-character sequence.n
The maximum number of wide characters that can be written to an array pointed to by s, including a terminating null wide character.format
A pointer to a wide-character string containing the format specifications. For more information about format and conversion specifications and their corresponding arguments, see Chapter 2....
Optional expressions whose resultant types correspond to conversion specifications given in the format specification.If no conversion specifications are given, the output sources can be omitted. Otherwise, the function calls 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 swprintf function is equivalent to the fwprintf function, except that the first argument specifies an array of wide characters instead of a stream.No more than n wide characters are written, including a terminating null wide character, which is always added (unless n is 0).
See also fwprintf in this section.
x The number of wide characters written, not counting the terminating null wide character. Negative value Indicates an error. Either n or more wide characters were requested to be written, or a conversion error occurred, in which case errno is set to EILSEQ.
Reads input from a wide-character string under control of the wide-character format string.
#include <wchar.h>int swscanf (const wchar_t *s, const wchar_t *format, ...);
s
A pointer to a wide-character string from which the input is to be obtained.format
A pointer to a wide-character string containing the format specifications. For more information about format and conversion specifications and their corresponding arguments, see Chapter 2....
Optional expressions whose results correspond to conversion specifications given in the format specification.If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have exactly as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers.
Conversion specifications are matched to input sources in left-to-right order. Excess input pointers, if any, are ignored.
The swscanf function is equivalent to the fwscanf function, except that the first argument specifies a wide-character string rather than a stream. Reaching the end of the wide-character string is the same as encountering EOF for the fwscanf function.See also fwscanf in this section.
x The number of input items assigned, sometimes fewer than provided for, or even 0 in the event of an early matching failure. EOF Indicates and error. An input failure occurred before any conversion.
Gets configurable system variables.
#include <unistd.h>long int sysconf (int name);
name
Specifies the system variable to be queried.
This function provides a method for determining the current value of a configurable system limit or whether optional features are supported.You supply a symbolic constant in the name argument, and sysconf returns a value for the corresponding system variable:
- The symbolic constants defined in the <unistd.h> header file.
- The system variables are defined in the <limits.h> and <unistd.h> header files.
Table REF-10 lists the system variables returned by the sysconf function, and the symbolic constants that you can supply as the name value.
x The current variable value on the system. The value does not change during the lifetime of the calling process. --1 Indicates an error. If the value of the name argument is invalid, errno is set to indicate the error.
If the value of the name argument is undefined, errno is unchanged.
Previous | Next | Contents | Index |