scanf读取时,遇到空格就停止读取而gets直到输入遇到换行符或EOF停止。
gets()读取时换行符不作为读取的内容,读取的换行符被转换为NULL,并由此来结束字符串。
gets()直接用在scanf后面时,要在之间插入一条gets()用于存储scanf结束时键入的回车符(换行符),否则该换行符会被当做gets()的结束符。
int total;
int i = 0;
char *temp;
char *line[ 100 ];
printf("please input the total number of lines:\n" );
scanf("%d", &total );
temp= ( char * )malloc( sizeof( char ) * INIT_LENGTH ); //这两行不能少,否则第一行会直接结束
gets(temp ); //
while( i < total ){
line[i ]= ( char * )malloc( sizeof( char ) * INIT_LENGTH );
gets(line[ i ] );
i++;
}