Using strncpy() : string function « Data Types « C++ Tutorial






#include <iostream>
 #include <string.h>
 
 int main()
 {
     const int MaxLength = 80;
     char String1[] = "test";
     char String2[MaxLength+1];
 
     strncpy(String2,String1,MaxLength);
     String2[strlen(String1)] = '\0'; // add a null to the end
     std::cout << "String1: " << String1 << std::endl;
     std::cout << "String2: " << String2 << std::endl;
     return 0;
 }
String1: test
String2: test








2.24.string function
2.24.1.Using strcpy()
2.24.2.Using strncpy()
2.24.3.strcpy, strlen, strcmp, strcat
2.24.4.Convert a string to uppercase.
2.24.5.Using strcat and strncat.
2.24.6.Using strcmp and strncmp
2.24.7.Using strtok
2.24.8.Using strlen