473,545 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_LENGT H];
collectInput(&i nputString);

and later on I have:

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

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

Regards
Michael
Jun 5 '06 #1
8 3254
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_LENGT H];
collectInput(&i nputString);

should be
collectInput(in putString);

or
collectInput(&i nputString[0]);

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

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

When you declare a variable like "char inputString[MAX_INPUT_LENGT H];"
inputString[MAX_INPUT_LENGT H]; , inputString itself becomes a pointer
to character ...So while calling above function you need to pass the
array name only..
So collectInput(&i nputString); line need to be modified to " collectInput(in putString);"
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_LENGT H];
collectInput(&i nputString);

and later on I have:

void collectInput(ch ar *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_LENGT H];
collectInput(&i nputString);
Try:

collectInput(in putString);

without the &
instead.

and later on I have:

void collectInput(ch ar *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_LENGT H], which is a pointer to an array.

Jun 5 '06 #5

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

Your function accepts a pointer to chanracter...No t a pointer to
pointer to a character.

When you declare a variable like "char inputString[MAX_INPUT_LENGT H];"
inputString[MAX_INPUT_LENGT H]; , 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_LENGT H])
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_LENGT H];
collectInput(&i nputString);


should be
collectInput(in putString);

or
collectInput(&i nputString[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*******@yaho o.fr> writes:
Ratan wrote:
>void collectInput(ch ar *input){
> scanf("%s", input);

Your function accepts a pointer to chanracter...No t a pointer to
pointer to a character.

When you declare a variable like "char inputString[MAX_INPUT_LENGT H];"
inputString[MAX_INPUT_LENGT H]; , 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 "inputStrin g itself becomes a pointer to
character".

--
Keith Thompson (The_Other_Keit h) 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_LENGT H];
collectInput (&inputString );


should be
collectInput( inputString);

or
collectInput( &inputString[0]);

&inputStrin g 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
17754
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: char skillkey; char (*fillkey_ptr)= skillkey;
15
9326
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': chris_readle_project3_assignment3.c:23: warning: passing arg 1 of `displaySales' from incompatible pointer type And here is the code in question:
1
2859
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 the remaining part of the program. I have combed the FAQ and got some preliminary questions answered, and tried to model this after what I have...
9
2547
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 *' to 'struct s_lsp_def *' In the .h file, I have ======================
7
90230
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
5249
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 easy for me to handle the single dimensional stream I have as a multidimensional array inside the function func(). Now, I am just wondering if there is...
8
24212
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 I cannot convince myself why this is prohibited. static int ia = {64, 64, 64, 64}; static char ca = {'a', 'b', 'c', 'd'}; static int iaa = {64,...
1
1519
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
2859
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
7502
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7791
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.