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

Kas*_*par 2 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;
    }
Run Code Online (Sandbox Code Playgroud)

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

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);
Run Code Online (Sandbox Code Playgroud)

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

Gri*_*han 5

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

printf("Ruutvõrrandi lahendid on: ", solution);
Run Code Online (Sandbox Code Playgroud)

应该:

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

  • @amit它只能在编译时检查.在运行时,被调用的函数不知道它获得了多少参数或它们的类型. (3认同)