Fehler: format '%d' erwartet, dass ein matching 'int' argument -wformat

Bekomme ich zwei Fehlermeldungen:

Error: format '%d' expects a matching 'int' argument -wformat

Error: format '%f' expects an arguemnt of double but argument 4 has type int -wformat

Ich es sah und versuchte, es zu beheben, ohne Erfolg. Unten ist mein code.

Könnte mir jemand sagen was ich falsch mache?

  #include <stdio.h>       
  int main() {
    int n = 5, a[5] = {1, 3, 5, 7, 9};  //Declare & initialize array of length 5
    int sum;
    int i;
    for (i = 1; i < n; i++) {
        sum = sum + a[i];

    printf("Enter an integer x: %d");       //Prompt the user
    int x;
    scanf("%d", &x);        //Read in the integer

    //Print out the sum, the division we're performing, and the result (without truncation)
    //E.g., The sum of the array is 25; 25/2 = 12.500000

    printf("The sum of the array is $d; %d/%d = %f\n", sum, sum, sum / x);

    //Declare an integer variable y and initialize it using a hexadecimal constant.
    //Print y in decimal, hex, and with leading zeros so that we get the output
    //y = 4011 = fab = 0xfab =   fab = 0000fab

    int y = 0xfab;
    printf("y = %d = %x\n", y, y, y, y, y);
    return 0;
  • Sie können nicht printf("Enter an integer x: %d"); ohne dass ein integer-Ausdruck als parameter. Die %d erfordert einen int-parameter, um zu Folgen. Auch printf("The sum of the array is $d; %d/%d = %f\n", sum, sum, sum / x); hat vier % Planern, aber nur 3 Parameter übergeben werden, Sie zu befriedigen.
  • "format '%f' erwartet, dass ein matching 'int' argument" - sind Sie sicher, das ist die genaue Meldung?
  • "format" %d "erwartet ein passendes argument int" und "format" %f "erwartet ein argument der doppelten, aber argument 4 hat Typ "int"
InformationsquelleAutor user3236142 | 2014-01-25
Schreibe einen Kommentar