Using strncpy() to assign one char array to another char array
#include <iostream>
#include <string.h>
int main()
{
const int MaxLength = 80;
char String1[] = "this is a test";
char String2[MaxLength+1] = {'\0'};
strncpy(String2, String1, MaxLength);
std::cout << "String1: " << String1 << std::endl;
std::cout << "String2: " << String2 << std::endl;
return 0;
}
Related examples in the same category