2017-10-20 145 views
0
char option; 
FILE *fp; 
errno_t err; 
err = fopen_s(&fp, "../AVL Trees/input.txt", "r"); 

while (!feof(fp)) 
{ 
    fscanf_s(fp, "%c", &option); //error is here 
    ... 
} 

这是AVL树项目。 我不明白为什么我有这个错误:“没有足够的参数通过格式”,我错过了什么?使用visual studio 2017错误:fscanf_s

编辑:

1>e:\visual studio projects\avl trees\avl trees\main.cpp(27): warning C4473: 'fscanf_s' : not enough arguments passed for format string 
1>e:\visual studio projects\avl trees\avl trees\main.cpp(27): note: placeholders and their parameters expect 2 variadic arguments, but 1 were provided 
1>e:\visual studio projects\avl trees\avl trees\main.cpp(27): note: the missing variadic argument 2 is required by format string '%c' 
1>e:\visual studio projects\avl trees\avl trees\main.cpp(27): note: this argument is used as a buffer size 
+0

通话变量选项声明? –

+0

我不认为它有多大帮助,但在这里它是(编辑) – Gundal

+0

与当前问题无关的其他方便阅读(但可能有助于下一个问题):[为什么是“while(!feof(file))”总是错?](https://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong) – user4581301

回答

0

C标准(K.3.5.3.2的fscanf_s功能)

4 The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a *). The first of these arguments is the same as for fscanf. That argument is immediately followed in the argument list by the second argument, which has type rsize_t and gives the number of elements in the array pointed to by the first argument of the pair. If the first argument points to a scalar object, it is considered to be an array of one element.

所以,你应该在哪里使用这样

fscanf_s(fp, "%c", &option, 1); 
相关问题