VS2013 fopen_s 用法

来源:互联网 发布:java b2b2c 开源下载 编辑:程序博客网 时间:2024/06/08 12:05

参考:

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\n" );   else      printf( "The file 'crt_fopen_s.c' was opened\n" );   // Open for write    if( (err = fopen_s( &stream2, "data2", "w+" )) != 0 )      printf( "The file 'data2' was not opened\n" );   else      printf( "The file 'data2' was opened\n" );   // Close stream if it is not NULL    if( stream)   {      if ( fclose( stream ) )      {         printf( "The file 'crt_fopen_s.c' was not closed\n" );      }   }   // All other files are closed:   numclosed = _fcloseall( );   printf( "Number of files closed by _fcloseall: %u\n", numclosed );}


scanf_s("%s",filename);//应有第三个参数指定filename中可以存入字符的个数,第三个参数默认为0,不重新指定则,filename中什么也得不到

应该例如:

scanf_s("%s",filename,10);

0 0
原创粉丝点击