473,503 Members | 12,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comple error when passing two dimensional char arrays as parameters

The following code won't compile with gcc version 3.4.2
(mingw-special).
How come?
Error: cannot convert `char (*)[80]' to `char**'

/************************************************** ********/
#include <cstdio>

#define MAX_WORD_LEN 80
#define MAX_SIZE 1000

void test (char* argv[]);

int main(int argc, char* argv[])
{
char words[MAX_SIZE][MAX_WORD_LEN];
test( words );
return 0;
}

void test (char* argv[])
{
}
/************************************************** ********/

Nov 16 '06 #1
3 3474
ZMan wrote:
The following code won't compile with gcc version 3.4.2
(mingw-special).
How come?
Error: cannot convert `char (*)[80]' to `char**'
See the FAQ (http://c-faq.com) section 6.18

--
Ian Collins.
Nov 16 '06 #2
ZMan wrote:
The following code won't compile with gcc version 3.4.2
(mingw-special).
How come?
Error: cannot convert `char (*)[80]' to `char**'

/************************************************** ********/
#include <cstdio>
C++ code is properly addressed in <comp.lang.c++>.
If you rewrite your code as C, invoke gcc as a C compiler (including
using the correct filename extension), and still have a problem, get
back to us.
Nov 17 '06 #3
Groovy hepcat ZMan was jivin' on 15 Nov 2006 23:43:48 -0800 in
comp.lang.c.
Comple error when passing two dimensional char arrays as parameters's
a cool scene! Dig it!
>The following code won't compile with gcc version 3.4.2
(mingw-special).
How come?
Error: cannot convert `char (*)[80]' to `char**'
Uh huh. As soon as I saw your subject line I knew what the problem
was. You're trying to pass a 2D array to a function expecting a
pointer to pointer. This is a mistake. Pointers and arrays are not the
same thing. This causes more confusion than a mouse at a burlesque
show. But it's really quite simple.
An array is converted to a pointer to its first element when passed
to a function. I'm sure you are aware of that. But you have to take
into account what it's an array of. An array of int is converted to a
pointer to int. An array of char is converted to a pointer to char. An
array of struct foo is converted to a pointer to struct foo. And so
on. Now, a 2D array is essentially an array of array. Thus, when
passed to a function it is converted to a pointer to array.
>#include <cstdio>
What on Earth is that? There ain't no sech animal in standard C.
Anyhow, you're not calling any library functions, so you don't need
any headers.
>#define MAX_WORD_LEN 80
#define MAX_SIZE 1000

void test (char* argv[]);
Here test() is declared as taking a pointer to pointer to char. I
know it looks like an array of pointer to char, but of course that
can't be so. It's a pointer to pointer to char.
>int main(int argc, char* argv[])
Since you're not using any of main()'s parameters, you can use the
parameterless version:

int main(void)
>{
char words[MAX_SIZE][MAX_WORD_LEN];
Here you declare an array of array of char.
test( words );
Now you pass that array of array of char to test(), and it is
converted to a pointer to array of char. But that won't do because
test() wants a pointer to pointer to char.
return 0;
}

void test (char* argv[])
{
}
Solution: you need to change test() to accept a pointer to array of
char.

void test(char (*argv)[MAX_WORD_LEN]);

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Nov 18 '06 #4

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

Similar topics

2
1483
by: Bill | last post by:
I have a string (holding a book title) that contains an apostrophe. This is generating an error when I try to pass it through sql into a table of orders. I retrieve it from the form with ...
2
1847
by: Tim Pascoe | last post by:
I'm trying to implement a sorting routine for a string array. The sort routine is from http://ourworld.compuserve.com/homepages/attac-cg/acgsoft.htm (a great selection of routines in the 'Sequence...
2
1474
by: ritchie | last post by:
Hi, Just wanted to ask if anybody has any idea what i'm doing wrong. I have a function which edits a linked list. It works fine. I pass in a pointer to the list plus the value of the item to...
32
4961
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
2
4930
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
2
1798
by: RogerInHawaii | last post by:
I would like to pass an array by reference to a function so that I can modify the contents of the array and effectively "return" that array to the caller. I tried doing this: function...
0
7212
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
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
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,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5604
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,...
0
3186
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...
0
1524
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 ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
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...

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.