473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

incompatible pointer type warning ?

Hi all,

why do I get a message:

warning: passing arg 1 of `collectInput' from incompatible pointer type

In 'main' have:

char inputString[MAX_INPUT_LENGTH];
collectInput(&inputString);

and later on I have:

void collectInput(char *input){
scanf("%s", input);
}

I know this is simple, but I can't see what's wrong.....

Regards
Michael
Jun 5 '06 #1
8 3244
Michael wrote:
Hi all,

why do I get a message:

warning: passing arg 1 of `collectInput' from incompatible pointer type

In 'main' have:

char inputString[MAX_INPUT_LENGTH];
collectInput(&inputString);

should be
collectInput(inputString);

or
collectInput(&inputString[0]);

&inputString is the address of the array, which in this case is a char**.

--
Ian Collins.
Jun 5 '06 #2
>void collectInput(char *input){
scanf("%s", input); Your function accepts a pointer to chanracter...Not a pointer to
pointer to a character.

When you declare a variable like "char inputString[MAX_INPUT_LENGTH];"
inputString[MAX_INPUT_LENGTH]; , inputString itself becomes a pointer
to character ...So while calling above function you need to pass the
array name only..
So collectInput(&inputString); line need to be modified to " collectInput(inputString);"
Michael wrote: Hi all,

why do I get a message:

warning: passing arg 1 of `collectInput' from incompatible pointer type

In 'main' have:

char inputString[MAX_INPUT_LENGTH];
collectInput(&inputString);

and later on I have:

void collectInput(char *input){
scanf("%s", input);
}

I know this is simple, but I can't see what's wrong.....

Regards
Michael


Jun 5 '06 #3
Michael wrote:

Hi all,

why do I get a message:

warning: passing arg 1 of `collectInput' from incompatible pointer type

In 'main' have:

char inputString[MAX_INPUT_LENGTH];
collectInput(&inputString);
Try:

collectInput(inputString);

without the &
instead.

and later on I have:

void collectInput(char *input){
scanf("%s", input);
}

I know this is simple, but I can't see what's wrong.....


The name of an array is automatically converted
to a pointer to it's first element in most cases,
such as the case above.

And make sure that inputString contains a string,
before passing it as an argument to a function
that takes a pointer to a string.

--
pete
Jun 5 '06 #4
Ian Collins wrote:

&inputString is the address of the array, which in this case is a char**.


No, the type of &inputString is not char**, which is a pointer to a
pointer, but char (*)[MAX_INPUT_LENGTH], which is a pointer to an array.

Jun 5 '06 #5

Ratan wrote:
void collectInput(char *input){
scanf("%s", input);

Your function accepts a pointer to chanracter...Not a pointer to
pointer to a character.

When you declare a variable like "char inputString[MAX_INPUT_LENGTH];"
inputString[MAX_INPUT_LENGTH]; , inputString itself becomes a pointer
to character ...So while calling above function you need to pass the
array name only..

No.
inputString doesn't become a pointer to a character (it is the C
language, not the B language).
inputString is an *array*.
&inputString is a pointer to an array (char (*)[MAX_INPUT_LENGTH])
which is not compatible with a pointer to char (char*).
array-to-pointer conversions occur very easily, but it arrays are not
pointers.

My post is not informative, since whyglinux already pointed that in
this discussion, but I say that in order to ensure that everybody in
this discussion will understand that.

Jun 5 '06 #6
Ian Collins wrote:
Michael wrote:

why do I get a message:

warning: passing arg 1 of `collectInput' from incompatible pointer type

In 'main' have:

char inputString[MAX_INPUT_LENGTH];
collectInput(&inputString);


should be
collectInput(inputString);

or
collectInput(&inputString[0]);

&inputString is the address of the array, which in this case is a char**.


No, it isn't a char**. While an array reference is often converted
to a pointer to its first element, that does not make the address
of an array a pointer to a pointer. Thinking of it as a char**
leads to gross errors.

Your actual code corrections are fine.

--
"Our enemies are innovative and resourceful, and so are we.
They never stop thinking about new ways to harm our country
and our people, and neither do we." -- G. W. Bush.
"The people can always be brought to the bidding of the
leaders. All you have to do is tell them they are being
attacked and denounce the pacifists for lack of patriotism
and exposing the country to danger. It works the same way
in any country." --Hermann Goering.
Jun 5 '06 #7
"SuperKoko" <ta*******@yahoo.fr> writes:
Ratan wrote:
>void collectInput(char *input){
> scanf("%s", input);

Your function accepts a pointer to chanracter...Not a pointer to
pointer to a character.

When you declare a variable like "char inputString[MAX_INPUT_LENGTH];"
inputString[MAX_INPUT_LENGTH]; , inputString itself becomes a pointer
to character ...So while calling above function you need to pass the
array name only..

No.
inputString doesn't become a pointer to a character (it is the C
language, not the B language).
inputString is an *array*.


The object called inputString is an array, and of course it doesn't
become anything.

The expression intputString, which is the name of an array, is
implicitly converted to a pointer to its first element in most
contexts, including this one. So in that sense, it's perfectly
correct to say that "inputString itself becomes a pointer to
character".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 5 '06 #8
CBFalconer wrote:
Ian Collins wrote:
Michael wrote:
why do I get a message:

warning: passing arg 1 of `collectInput' from incompatible pointer type

In 'main' have:

char inputString[MAX_INPUT_LENGTH];
collectInput(&inputString);


should be
collectInput(inputString);

or
collectInput(&inputString[0]);

&inputString is the address of the array, which in this case is a char**.

No, it isn't a char**. While an array reference is often converted
to a pointer to its first element, that does not make the address
of an array a pointer to a pointer. Thinking of it as a char**
leads to gross errors.

Oops, my bad.

--
Ian Collins.
Jun 5 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Stubblefield | last post by:
Dear clc members, I am rather new to the C programming language. I have a rather large program that I am currently debugging. Currently, the following snippet of code in the c program: ...
15
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
1
by: Josh Wilson | last post by:
Hey gang, So I have my stdin which is user defined file, and am wanting to write it to a temporary file (seems odd I know, but there is a sincere reason), and then use that file as the stdin for...
9
by: Ali | last post by:
incompatible warning in C/C++ I am using MS Visual C/C++ 6.0. I get the following warning when compiling C:model.ex.c(1221) : warning C4133: '=' : incompatible types - from 'struct s_lsp_def...
7
by: Paminu | last post by:
On a gentoo linux system i don't get any warnings when I comlpile this code: #include <stdio.h> typedef struct test { void *content; struct test_ *bob; } test_;
6
by: PraZ | last post by:
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it...
8
by: fei.liu | last post by:
I have the following source code. It seems wierd to me why gca's value cannot be reassigned. It's afterall a pointer and has a pointer value. I am aware that the standard says it's not allowed. But...
1
by: wanglei0214 | last post by:
I compiles a program in SLOS, but there is a warning i donot know how to remove? here is the framework of the code: typedef struct device_tree { ...... union {
1
by: pyo2004 | last post by:
Here's the definition of work_struct struct work_struct { unsigned long pending; struct list_head entry; void (*func)(void *); void *data; void *wq_data; struct timer_list timer; };
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.