user3590350
user3590350

Reputation: 25

C programing format '%s' expects type 'char*', but argument 2 has 'char *[50]

this is one function receiving the error but for the life of me I cant figure out why

void serchName(dealers_t *ptr, int numDealers)   
{
    char dealerName[NAME_LEN];
    int index;

    printf("please enter the dealer's name:");
    scanf("%s", &dealerName);

    for (index = 0; index < numDealers; index++, *ptr++)
    {
        if (strcmp(dealerName, ptr->name) == 0)
        {
            printf("name: %s\n city: %s\n state:%s\n zip:%i\n phone: %s\n", ptr->name,ptr->city,ptr->state,ptr->zip,ptr->phone);
        }
    }
}

Upvotes: 1

Views: 837

Answers (1)

sarath
sarath

Reputation: 543

If you pass a char [50] to scanf(), it will see that as a char * that points to the first element to the array. That's why you don't have to explicitly use the "addressof" (&) operator for a (char) array.

If you use it, you don't get a pointer to the first element of the array, but a pointer to the array itself, and that's why the compiler is giving warning.

Upvotes: 1

Related Questions