Em đang dùng bản 2013 mà nó cứ bắt phải dùng fopen_s. Em đọc trên mạng và làm theo hướng dẫn nhưng không được. Cách sử dụng hàm này như thế nào?
Cách sử dụng hàm fopen_s?
Trong link này có hướng dẫn sử dụng của Microsoft
https://msdn.microsoft.com/en-us/library/z5hh6ee9.aspx
Code em code như thế nào mà không được? Sau này hỏi code phải có code nhé.
Em code sai rồi, danhsach là FILE, em phải tạo thêm một cái errno_t để nhận giá trị trả về của fopen_s. Em xem cái hướng dẫn của cái link anh gửi nhé
// 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 )
{
errno_t err;
// Open for read (will fail if file "crt_fopen_s.c" does not exist)
err = fopen_s( &stream, "crt_fopen_s.c", "r" );
if( err == 0 )
{
printf( "The file 'crt_fopen_s.c' was opened\n" );
}
else
{
printf( "The file 'crt_fopen_s.c' was not opened\n" );
}
// Open for write
err = fopen_s( &stream2, "data2", "w+" );
if( err == 0 )
{
printf( "The file 'data2' was opened\n" );
}
else
{
printf( "The file 'data2' was not opened\n" );
}
// Close stream if it is not NULL
if( stream )
{
err = fclose( stream );
if ( err == 0 )
{
printf( "The file 'crt_fopen_s.c' was closed\n" );
}
else
{
printf( "The file 'crt_fopen_s.c' was not closed\n" );
}
}
// All other files are closed:
int numclosed = _fcloseall( );
printf( "Number of files closed by _fcloseall: %u\n", numclosed );
}
#include <stdio.h>
#include <conio.h>
int main()
{
errno_t file_in;
FILE *FileIn;
file_in = fopen_s(&FileIn, "INPUT.TXT", "r");
//Kiểm tra xem file có tồn tại hay không
if (!FileIn)
{
printf("Khong ton tai file INPUT.TXT\n");
_getch();
return 0;
}
_getch();
return 0;
}
Em viết trên VS2013, file INPUT e đã tạo rồi mà sao lệnh if vẫn hoạt động vậy anh @ltd , a giúp e chỗ này.

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?