开发者

what are the differences between scanf() and fscanf()?

what are the differences between scanf() and fscanf(开发者_如何学C)?

thanks


scanf() is exactly identical to fscanf() with stdin as the first argument.


For scanf() you always read from standard input and for fscanf() you specify the file input stream.

Compare:

int  scanf ( const char * format, ... );
int fscanf ( FILE * stream, const char * format, ... );


Just google it (emphasis mine):

http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

int  scanf ( const char * format, ... );

Read formatted data from stdin

And

http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/

int fscanf ( FILE * stream, const char * format, ... );

Read formatted data from stream


From the third paragraph of fscanf(3) manpage:

   The scanf() function reads input from the standard input stream
   stdin, fscanf() reads input from the stream pointer stream, and
   sscanf() reads its input from the character string pointed to by
   str.

You might have been able to guess that from the SYNOPSIS:

   int scanf(const char *format, ...);
   int fscanf(FILE *stream, const char *format, ...);

:)


scanf() : data transfer from I/O to memory(variables) fscanf() : data transfer form memory(variables) to file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜