0

从http://festvox.org/ ...直接通过运行通用脚本安装节日语音合成系统。面对下面给出的问题.....这个问题会影响我在节日框架上的工作吗??????

eps.c: In function ‘getd’:

eps.c:142:7: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]

   fscanf(fp, "%d %d", x, y);
   ^
4

3 回答 3

3

阅读fscanf(3)的文档。您应该使用成功扫描项目的返回计数,例如代码如下:

int x = 0, y = 0;
if (fscanf(fp, "%d %d", &x, &y) < 2) {
   fprintf(stderr, "missing numbers at offset %ld\n", ftell(fp));
   exit(EXIT_FAILURE);
}

因此您可以改进eps.c文件(并可能在上游提交补丁和/或错误报告)。

于 2015-08-23T12:05:46.463 回答
0

这个警告说不检查 scanf 的返回值并不是一个好主意。

我认为强制转换(void)是一种避免这种情况的方法,但显然它不像这里讨论的那样:https ://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509

但是,您得到的不是错误,而只是警告(您的标题有点误导)

如果不使用该值,则显然不是问题。

于 2015-08-23T12:07:20.843 回答
0

手册页说:

如果在第一次成功转换或匹配失败发生之前到达输入结尾,则返回值 EOF。如果发生读取错误,也会返回 EOF,在这种情况下会设置流的错误指示符(请参阅 ferror(3)),并设置 errno 以指示错误。

这意味着您可以检查 EOF:

#include<stdio.h>

int main(void){
    int a;
    printf("Please give the value of A: ");

    if(scanf("%d",&a) != EOF){
        printf("\nThe value of A is\t%d\n",a);
    }

    return 0;
}

或者:

#include<stdio.h>
#include <errno.h>
#include<string.h>

int main(void){
    int a, errnum = errno;
    printf("Please give the value of A: ");

    if(scanf("%d",&a) == EOF){
        fprintf(stderr, "Value of errno: %d\n", errno);
        perror("Error printed by perror");
        fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
    }

    printf("\nThe value of A is\t%d\n",a);
    return 0;
}

这适用于:

scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf - 输入格式转换

于 2015-08-23T13:09:42.697 回答