strcpy in cpp code example

Example 1: c++ strcpy_s

//When to use strcpy_s:
//	Use strcpy_s to copy a const char[] array in read and write memory
//How to use strcpy_s:

//The location where the array is going to be copied to
char* ptrToArray = new char[sizeof(testArray)]

//The Array that gets copied To ptrToArray;
const char[] testArray = "Test Array";

strcpy_s(ptrToArray, sizeof(testArray), testArray);

//Modify the copied array
testArray[i] = 'A'

Example 2: 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; 
}

Example 3: strcmp c++

int strcmp ( const char * str1, const char * str2 );

// returning value | indicates
// <0	the first character that does not match has a lower value in ptr1 than in ptr2
// 0	the contents of both strings are equal
// >0	the first character that does not match has a greater value in ptr1 than in ptr2

Tags:

Cpp Example