strcpy in c++ code example
Example 1: c++ strcpy_s
char* ptrToArray = new char[sizeof(testArray)]
const char[] testArray = "Test Array";
strcpy_s(ptrToArray, sizeof(testArray), testArray);
testArray[i] = 'A'
Example 2: strcpy
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[]="Sample string";
char str2[40];
char str3[40];
strcpy (str2,str1);
strcpy (str3,"copy successful");
printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
return 0;
}
Example 3: strcmp c++
#include<stdio.h>
#include<string.h>
int main()
{
char char1[] = "coucou";
char char2[] = "coucou";
if( strcmp(char1, char2) == 0 )
printf("Strings are the same");
else
prinf("Strings are differentes");
return 0;
}