/*C語言 字串陣列的複製*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char name1[5][10] = { "apple","banana","cat","dog","egg" };
/*宣告字串陣列:char 字元陣列名稱[字串數][字串長度]*/
char name2[5][10];
int i, j;
for (i = 0; i < 5; i++)
{
if (name1[i] == '\0')
break;
for (j = 0; j < 10; j++)
name2[i][j] = name1[i][j];
}
for(i = 0;i<5;i++)
printf("name[%d]=%s\n", i, name2[i]);
system("pause");
return 0;
}
結果為:
文章標籤
全站熱搜
留言列表