VSS 2013 fopen_s用法
1430 ワード
参考:
http://bbs.csdn.net/topics/190162053
例えば、
scanfs("%s",filename,10);
http://bbs.csdn.net/topics/190162053
//
// crt_fopen_s.c
// This program opens two files. It uses
// fclose to close the first file and
// _fcloseall to close all remaining files.
#include <stdio.h>
FILE *stream, *stream2;
int main( void )
{
int numclosed;
errno_t err;
// Open for read (will fail if file "crt_fopen_s.c" does not exist)
if( (err = fopen_s( &stream, "crt_fopen_s.c", "r" )) !=0 )
printf( "The file 'crt_fopen_s.c' was not opened
" );
else
printf( "The file 'crt_fopen_s.c' was opened
" );
// Open for write
if( (err = fopen_s( &stream2, "data2", "w+" )) != 0 )
printf( "The file 'data2' was not opened
" );
else
printf( "The file 'data2' was opened
" );
// Close stream if it is not NULL
if( stream)
{
if ( fclose( stream ) )
{
printf( "The file 'crt_fopen_s.c' was not closed
" );
}
}
// All other files are closed:
numclosed = _fcloseall( );
printf( "Number of files closed by _fcloseall: %u
", numclosed );
}
scanfs("%s",filename)///3番目のパラメータが指定されているはずです。filenameには文字の個数を入れられます。3番目のパラメータはデフォルトで0です。再指定しないと、filenameには何も得られません。例えば、
scanfs("%s",filename,10);