visual-studio-2015 - 我不能在 VS2019 中使用“fscanf”
解决方案
不要使用 fscanf 它是不安全的,不应再使用,使用 fscanf_s。C 是一门古老的语言,因此它有很多不应该使用且无法删除的内容。
// crt_fscanf_s.c
// This program writes formatted
// data to a file. It then uses fscanf to
// read the various data back from the file.
#include <stdio.h>
#include <stdlib.h>
FILE *stream;
int main( void )
{
long l;
float fp;
char s[81];
char c;
errno_t err = fopen_s( &stream, "fscanf.out", "w+" );
if( err )
printf_s( "The file fscanf.out was not opened\n" );
else
{
fprintf_s( stream, "%s %ld %f%c", "a-string",
65000, 3.14159, 'x' );
// Set pointer to beginning of file:
fseek( stream, 0L, SEEK_SET );
// Read data back from file:
fscanf_s( stream, "%s", s, _countof(s) );
fscanf_s( stream, "%ld", &l );
fscanf_s( stream, "%f", &fp );
fscanf_s( stream, "%c", &c, 1 );
// Output data read:
printf( "%s\n", s );
printf( "%ld\n", l );
printf( "%f\n", fp );
printf( "%c\n", c );
fclose( stream );
}
}
推荐阅读
- file - File scanner loop does not execute
- python - Why can't the server machine in travis CI locate my requirements file?
- c# - C# - Is overloading methods with different types more performant than using type checking in a single method?
- c# - 如何使用 VSIX 扩展、C# 执行 Keras.Net
- angular - *ngFor with default image
- python - django 无法发布数据
- c# - Ignore a property with PropertyInfo
- machine-learning - NLP Transformers: Best way to get a fixed sentence embedding-vector shape?
- java - 在 TransformerFactory 中设置安全处理会导致 XSL 出现问题
- c# - 使用实体框架按名称获取表