|
// StringCopy.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <atlstr.h>
#define MAX_CHAR 255
#define BUFSIZE 85
#include <strsafe.h>
int _tmain(int argc, _TCHAR* argv[])
{
/* declare unsafe copy variable */
wchar_t unsafe_copy_str1[]=L"Hello world";
wchar_t unsafe_copy_str2[MAX_CHAR];
/* demo unsafe wcscpy without buffer check */
wprintf(L"#### String Copy demo using wcscpy #### \n");
wcscpy (unsafe_copy_str2, unsafe_copy_str1);
wprintf (L"After copy string = %s\n\n", unsafe_copy_str2);
/* declare safe CRT variable */
wchar_t safe_copy_str1[]=L"Hello world";
wchar_t safe_copy_str2[MAX_CHAR];
/* demo safe CRT variable */
wprintf(L"#### String Copy demo using wcscpy_s #### \n");
wcscpy_s( safe_copy_str2, _countof(safe_copy_str1),safe_copy_str1 );
wprintf (L"After copy string = %s\n\n", safe_copy_str2);
/* declare strsafe variable */
wchar_t safe_copy_str3[]=L"Hello world";
wchar_t safe_copy_str4[MAX_CHAR];
/* demo strsafe variable */
wprintf(L"#### String Copy demo using StringCchCopy #### \n");
HRESULT Res;
Res=StringCchCopy(STRSAFE_LPWSTR(safe_copy_str4), sizeof(safe_copy_str4), STRSAFE_LPWSTR(safe_copy_str3));
if (Res != S_OK) {
wprintf(L"StringCbCopy Failed: %s\n", safe_copy_str4);
exit(-1);
}
wprintf (L"After copy string = %s\n\n", safe_copy_str4);
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Selvam has worked on several technologies like Java, Python, Big data, VC++, MFC, Windows API and Weblogic server. He takes a lot of interest in reading technical articles and enjoys writing them too. He has been awarded as a Microsoft Community Star in 2004, MVP in 2005-06, SCJP 5.0 in 2009, Microsoft Community Contributor(MCC) 2011.
Big Data
o Google Professional Data Engineer 2021
o Confluent Certified Developer for Apache Kafka 2020
o Datastax Apache Cassandra 3.x Developer Associate Certification 2020
✓ Cloud
o Google Professional Cloud Architect 2021
o Microsoft Certified: Azure Solutions Architect Expert 2020
o AWS Certified Solutions Architect - Associate 2020
✓ Oracle Certified Master, Java EE 6 Enterprise Architect (OCMEA) 2018
Github :
https://github.com/selvamselvam
Web site:
http://www.careerdrill.com
Linkedin:
https://www.linkedin.com/in/selvamselvam/