下面代碼演示了程序循環從用戶輸入讀取字符串,并存入臨時的字符串數組,然后將臨時字符串復制到qwords數組里面。
#include<stdio.h>
#include<string.h>
#define SIZE 40
#define LIM 5
int main(void)
{
char qwords[LIM][SIZE];
char temp[SIZE];
int i=0;
while(i<LIM && gets(temp))
{
strcpy(qwords[i],temp);
i++;
}
puts("The list");
for(i=0;i<LIM;i++)
{
puts(qwords[i]);
}
getchar();
return 0;
}