64,649
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void test1(){
char str[10];
char *str1 = "0123456789";
strcpy(str, str1);
cout << str << "\t" << str1 << endl;
}
void test2(){
char str[10], str1[10];
for(int i = 0; i < 9; i++){
str1[i] = 'a' + i;
}
str1[9] = '\0';
strcpy(str, str1);
cout << str << "\t" << str1 << endl;
}
void test3(char *str1){
char str[10];
if(strlen(str1) <= 10){
strcpy(str, str1);
}
cout << str << "\t" << str1 << endl;
}
int main(){
test1();
test2();
char *str = "0123456789";
test3(str);
return 0;
}
void test1(){
char str[12];
char *str1 = "0123456789";
strcpy(str, str1);
cout << str << "\t" << str1 << endl;
}
void test2(){
char str[10], str1[10];
for(int i = 0; i < 9; i++){
str1[i] = 'a' + i;
}
str1[9] = '\0';
strcpy(str, str1);
cout << str << "\t" << str1 << endl;
}
void test3(char *str1){
char str[11];
if(strlen(str1) <= 10){
strcpy(str, str1);
}
cout << str << "\t" << str1 << endl;
}
int main(){
test1();
test2();
char *str = "0123456789";
test3(str);
return 0;
}