int main() {
char src[] = "santosh";
char dest[0];
strncpy(dest, src, 4);
printf("%s\n", dest); // expecting o/p "sant" but o/p was "santtosh"
int i = 0;
while (dest[i])
私は最初の2つをコピーして配列に追加し、中間の2つをコピーして最後の2つを追加して追加しますそれらを配列に変換します。 これは私が何をすべきかです: char color1[2];
char color2[2];
char color3[2];
strncpy(color1, string, 2); // I take the first two characters and put th
strncpyの文字数を考慮して、よりクリーンで効率的な方法があるかどうか疑問に思っています。私はそれを過ぎているように感じる。 int main(void)
{
char *string = "hello world foo!";
int max = 5;
char *str = malloc (max + 1);
if (str == NU