-1

just to let you all know im pretty new at programming and i think I am just missing something small but I dont know what it is. When I compile my code I am getting this error "format %d expects a matching int argument [-Wformat=]". I have tried many things. I have tried making all the function types to char and them all to int. I get similar errors.

char *phoneInput(void)
{
    char phone[11];

    printf("Input the politicians phone number with no spaces: ");
    fgets(phone, 10, stdin);
    return 0;
}

char  printPhone(char phone[11])
{
    printf("- Phone Number: (%d%d%d)%d%d%d-%d%d%d%d", phone[0], phone[1], phone[2], 
              phone[3], phone[5], phone[6], phone[7], phone[8], phone[9]);

    return 0;
}
Duck Dodgers
  • 3,409
  • 8
  • 29
  • 43
sarah
  • 59
  • 1
  • 5
  • 2
    I suggest you do some [rubber duck debugging](https://en.wikipedia.org/wiki/Rubber_duck_debugging) of your code. That `phoneInput` functions looks very suspect... – Some programmer dude Feb 04 '19 at 13:17
  • And please read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to create a [mcve] to show us. – Some programmer dude Feb 04 '19 at 13:18
  • The error seems pretty clear if you read the words. `**char** phone[11]` and *format '%d' expects a matching **'int`** argument* should be pretty self explanatory. – Ken White Feb 04 '19 at 13:21
  • 2
    `phone` is local to `phoneInput` function. It will not be visible outside of that function scope. You have to declare `phone` as a pointer and dynamically allocate memory for it and return `phone` pointer from `phoneInput` function. In function `printPhone`, function specification should be `%c` instead of `%d`. – haccks Feb 04 '19 at 13:24
  • I tried using %c instead of %d and i get a similar error format ‘"%c’ expects a matching ‘int’ argument [-Wformat=]" – sarah Feb 04 '19 at 13:25
  • 4
    Basically your error is because you have 10 `%d`s and only nine matching arguments. – hat Feb 04 '19 at 13:28

1 Answers1

1

You are missing one more argument for your printf statement. Add phone[4] to your printf like this.

#include <iostream>

using namespace std;

char *phoneInput(void)
{
    char phone[11];

    printf("Input the politicians phone number with no spaces: ");
    fgets(phone, 10, stdin);
    return 0;
}

char  printPhone(char phone[11])
{
    printf("- Phone Number: (%d%d%d)%d%d%d-%d%d%d%d", phone[0], phone[1], phone[2],
              phone[3], phone[4], phone[5], phone[6], phone[7], phone[8], phone[9]);

    return 0;
}

But I don't understand is, why all your functions have a return type of char* or char when in fact from both functions, you are returning a 0 only.

Duck Dodgers
  • 3,409
  • 8
  • 29
  • 43