基本的に私がしなければならないことは、自分のc-stringを作り直すことです。strlen、strcmp、strcpy、および strcat。以下のコードは私のヘッダーファイルにあります:
int mystrlen(const char pcString[]) //strlen function
{
const char *pcStringEnd = pcString;
while (*pcStringEnd != '\0')
pcStringEnd++;
return pcStringEnd - pcString;
}
int mystrcmp(char *s1, char *s2) // strcmp function
{
while(*s1 == *s2)
{
if(*s1 == '\0' || *s2 == '\0')
break;
first++;
second++;
}
if(*first == '\0' && *second == '\0')
return (0);
else
return (-1);
}
char mystrcpy(char *s1, const char *s2) // strcpy function
{
while(*s2)
{
*s1 = *s2;
s2++;
s1++;
}
*s1 = '\0';
}
char mystrcat(char *s1, const char *s2) //strcat function
{
char *string1 = s1;
const char *string2 = s2;
char *catString = string1 + string2;
return catString;
}
ほとんどのエラーは識別子が定義されていないことですが、問題は main.cpp の内容を変更できないことです。ヘッダー ファイルのみを変更できます。ここに main.cpp を配置しますが、長いコードです。
{
char *string1 = s1;
const char *string2 = s2;
char *catString = string1 + string2; //There is an error here with string 2 and catring.
return catString;
}