Reputation: 97
I'm still trying to wrap my head around pointers and strings in C for a class I'm taking. In the below example, g_reservations[][] is a global variable (not ideal, I know, but I cant change that).
error: Warning C4047 'function': 'const char *' differs in levels of indirection from 'char' EconoAirBeta ... 299
*passenger is a pointer, so do create a pointer to the global? That seems unnecessary...
how do i make this work? I feel I'm missing some incredibly easy concept my brain cant seem to grasp....
unsigned int FindSeatWithPassenger(const char *passengerName)
{
unsigned int seat = 0;
for (seat = 0; seat < NUM_SEATS; ++seat)
{
if ( strncmp(passengerName, g_reservations[seat][0], NAME_LENGTH) != 0) //error here with global variable
{
return seat;
break;
}
}
return '\0';
}
Global declaration:
#define NAME_LENGTH 10
#define NAME_BUFFER_LENGTH ( NAME_LENGTH + 1 )
char g_reservations[NUM_SEATS][NAME_BUFFER_LENGTH];
Upvotes: 0
Views: 60
Reputation: 154242
Wrong type
Just as the error says.
g_reservations[seat][0]
is a char
.
int strncmp(const char *s1, const char *s2, size_t n)
expects a char *
for s2
.
Use &g_reservations[seat][0]
or simply g_reservations[seat]
strncmp(passengerName, g_reservations[seat], NAME_LENGTH)
Upvotes: 3