为了便于阅读,我删掉了很多代码。具体来说,我正在尝试重写 strcat
#include <iostream>
using namespace std;
char MYstrcat(char string1[],char string2[]);
int main()
{
char letter, letter_ans, again;
const int SIZE = 80;
char string1 [SIZE];
char string2 [SIZE];
获取字符数组的输入
cout << "Enter the first string: ";
cin >> string1;
cout << "Enter the second string: ";
cin >> string2;
letter_ans=MYstrcat(string1, string2);
cout << letter_ans;
cin.get(); cin.get();
return 0;
}
这是我的 strcat 函数版本
char MYstrcat(char string1[],char string2[])
{
int i = 0; //Counters
int j = 0;
//Read until null character is encountered then append.
while (string1[i] != '\0')
{
i++;
}
while (string2[j]!= '\0'){
string1[i] = string2[j];
i++;
j++;
}
string1[i]='\0'; // Place a null character in string2.
我在下一行得到错误:从'char *'到'char'的无效转换
return string1;
}