哪位学长能给解释一下?
#include <stdio.h>#include <stdlib.h>
#define MAX 100
int main( void )
{
FILE *fp;
char words[ MAX ];
if( ( fp = fopen( "3.txt", "a+" ) ) == NULL ){
fprintf( stderr, "The file opening failed!\n" );
exit( EXIT_FAILURE );
}
else{
while( gets( words ) != NULL && words[ 0 ] != '\0' )
fprintf( fp, "%s", words );
puts( "File contents:" );
rewind( fp );
while( fscanf( fp, "%s", words ) == 1 )
puts( words );
fclose( fp );
}
}
为什么我输入的是一行句子,输出却是单个单词??给讲讲原理,谢谢!