December 2005
Beginner to intermediate
618 pages
20h 19m
English
wmemcpy
Copies the contents of a block of wide characters
#include <wchar.h> wchar_t *wmemcpy( wchar_t * restrictdest, const wchar_t * restrictsrc, size_tn);
The wmemcpy() function
copies n successive wide characters
beginning at the address in src to the
location beginning at the address in
dest. The return value is the same as the
first argument, dest. The two pointer
values must be at least n wide characters
apart, so that the source and destination blocks do not overlap;
otherwise, the function’s behavior is undefined. For overlapping
blocks, use wmemmove().
#define BUFFERSIZE 2048 // Size as a number of wchar_t elements. wchar_t inputbuffer[BUFFERSIZE] = { L'\0' }, *writeptr = inputbuffer; struct block { wchar_t *text; struct block *next; struct block *prev; } firstblock = { NULL }, *tmp = NULL; // The first block is the list head. struct block *newblock( struct block *lastblock ); // Creates a linked-list member. wchar_t *storetext( struct block *listhead, wchar_t *buffer, size_t bufsize ); // Copies input buffer to a new linked-list member. int main() { while ( fgetws( writeptr, BUFFERSIZE − (writeptr − inputbuffer), stdin ) != NULL ) { // Set writeptr to end of the input string: writeptr = wmemchr( inputbuffer, L'\0', sizeof(inputbuffer) / sizeof(wchar_t) ); if ( BUFFERSIZE − (writeptr − inputbuffer) < 80 ) // If block full, or nearly so: { // copy buffer to a data block. writeptr = storetext( &firstblock, inputbuffer, BUFFERSIZE ); if ( writeptr == NULL ...Read now
Unlock full access