C程序提供了太多的参数警告

时间:2014-01-30 15:34:55

标签: c

所以我有这个代码,我尝试解决一些简单的数学:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

float ruutvorrand(float a, float b, float c);

int main(void) {  
    float a;
    float b;
    float c;
    float solution;

    printf("Ruutvõrrandi lahedamine\nSisesta andmed: ");
    scanf("%f %f %f", &a, &b, &c);
    solution = ruutvorrand(a, b, c);
    printf("Ruutvõrrandi lahendid on: ", solution);
    return 0;
    }

float ruutvorrand(float a, float b, float c) {
    float out;
    float upper;
    float upper1;
    upper = sqrt((b * 2)-(4 * a * c));
    upper1 = (-b + upper);
    out = upper1 / (2 * a);
    return out;
    }

问题在于,当我尝试编译它时,我收到此错误:

gcc yl3.c -o ruut -lmyl3.c: In function ‘main’:
yl3.c:16:5: warning: too many arguments for format [-Wformat-extra-args]
     printf("Ruutvõrrandi lahendid on: ", solution);

现在我在这里做错了什么。我真的给这个功能太多了吗?

4 个答案:

答案 0 :(得分:5)

你忘记了printf中的格式字符串:

printf("Ruutvõrrandi lahendid on: ", solution);

应该是:

printf("Ruutvõrrandi lahendid on: %f", solution);
 //                                ^ %f because soulution in float     

答案 1 :(得分:2)

这是因为语句

中没有solution的说明符
printf("Ruutvõrrandi lahendid on: ", solution);  

%f需要solution说明符才能打印出来。

printf("Ruutvõrrandi lahendid on: %f", solution);

答案 2 :(得分:0)

您的上次printf()缺少solution ...

的格式

答案 3 :(得分:0)

u错过了printf语句中的格式说明符

 printf("Ruutvõrrandi lahendid on: ", solution);  

应该是

 printf("Ruutvõrrandi lahendid on: %f", solution);