StrCpyNStrCpyN*
*Contents  *Index  *Topic Contents
*Previous Topic: StrCmpNI
*Next Topic: StrCSpn

StrCpyN


LPTSTR StrCpyN(
    LPCTSTR psz1,
    LPCTSTR psz2, 
    int cchMax
    );

#define StrNCpy StrCpyN

Copies a specified number of characters from one string to another. The StrNCpy macro differs from this function in name only.

psz1
Address of the destination string.
psz2
Address of the source string.
cchMax
Number of characters to be copied, including the null.

Example:

#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main( void )
{
  //String one
  char buffer_1[] = "ABCDEFG";
  char *lpStr1;
  lpStr1 = buffer_1;

  //String two
  char buffer_2[] = "HIJKLMN";
  char *lpStr2;
  lpStr2 = buffer_2;

  cout  <<  "The function StrCpyN will allow you to copy (n) numbers"
  <<  "\nof characters from the string 2 to string 1."
  <<  "\nString 1 is : "	<< lpStr1
  <<  "\nString 2 is : "	<< lpStr2
  <<  "\nCopy (n) from 2 onto 1" << endl;
cout  <<  StrCpyN(lpStr1,lpStr2,8)
}


OUTPUT:
- - - - - -
The function StrCpyN will allow you to copy (n) numbers
of characters from the string 2 to string 1.
String 1 is : ABCDEFG
String 2 is : HIJKLMN
Copy (n) from 2 onto 1 
HIJKLMN

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.