user3024406
user3024406

Reputation: 3

Error incompatible pointer type?

#include<stdio.h>
#include<string.h>

char getInput(char *x[50]);

main (){

char string[50];
getInput(&string);
}

char getInput(char *x[50]){
printf("What is the string?");
gets(*x);   
}   

I keep getting these errors...

exer7.c:20:2: warning: passing argument 1 of ‘getInput’ from incompatible pointer type [enabled by default] getInput(&string); ^ exer7.c:5:6: note: expected ‘char *’ but argument is of type ‘char ()[50]’ char getInput(char *x[50]);

I've been changing the pointers and ampersands but I really don't know the proper pointer type, pls help :(

BTW, that's just a code snippet, I have many other user-declared functions I don't need to post here.

Upvotes: 0

Views: 1299

Answers (3)

BLUEPIXY
BLUEPIXY

Reputation: 40145

void getInput(char (*x)[50]);

int main (){
    char string[50];
    getInput(&string);
    return 0;
}

Upvotes: 1

Sunil Bojanapally
Sunil Bojanapally

Reputation: 12658

getInput(&string); You shouldn't pass & of string. Just base address string of the char array need to be passed as the argument.

char getInput(char *x[50]); This formal argument isn't correct too. This should be a pointer to char or array of char of 50 bytes.

Upvotes: 0

haccks
haccks

Reputation: 106012

char *x[50] declares x as array of pointers.&string` is of type pointer to an array. Both types are incompatible.

Change your function declaration to

char getInput(char x[50]);   

and call it as

 getInput(string);

Upvotes: 1

Related Questions