構造体の文字列を初期化する手作業はありますか?あなたはもうstrcpy
を使用していないstrcpy関数を使わずにstruct内の文字列を初期化する方法は?
void mycopy(char *dest, const char *source, size_t ndest)
{
assert(ndest != 0);
while (--ndest > 0 && (*dest++ = *source++))
;
}
:あなたはstrcpy
の独自のバージョンを書くことができ
typedef struct {
int id;
char name[20];
int age;
} employee;
int main()
{
employee x;
x.age=25;
strcpy(x.name,"sam");
printf("employee age is %d \n",x.age);
printf("employee name is %s",x.name);
return 0;
}
'社員X =末尾含む;' – BLUEPIXY
なぜ?あなたの質問がばかげているように見えるので、理由を説明してください。 – gnasher729
を固定長配列にコピーするには、strncpy()またはstrncpy_s(使用可能な場合)を常に使用する必要があります。 –