赋值地址的问题~~
程序的来源是《c primer plus》第十一章第10题,这里面我不懂的是if ( gets(str[n]) == NULL ) break;后为什么不直接使用输入的str[]字符串,而是现将str[]地址赋给p[],p[]=str[]; 求指教!!! 部分程序如下:
程序代码:
int main(void)
{
char str[10][81];
char *p[10];
char command[10];
int n;
while(1)
{
n = 0;
puts("input no more than 10 strings finished by EOF (^Z):");
do
{
if ( gets(str[n]) == NULL ) break;
p[n] = str[n];
n++;
}
while( n<10 );
puts("select:");
puts("a. put originally");
puts("b. put in order of ascii");
puts("c. put in order of string's length");
puts("d. put in order of first word's length");
puts("e. input strings again");
puts("q. quit");
do
{
gets(command);
switch(command[0])
{
case 'a': puts("put originally:"); origin_put(p,n); break;
case 'b': puts("put in order of ascii:"); ascii_put(p,n); break;
case 'c': puts("put in order of string's length:"); length_put(p,n); break;
case 'd': puts("put in order of first word's length:"); word_put(p,n); break;
case 'e': break;
default : puts("Quit."); return 0;
}
}
while( command[0] != 'e' );
}
}









