473,394 Members | 1,724 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,394 software developers and data experts.

How to resolve "Error:initialization from incompatible pointer type" ?

Below is my code snippet.I'm getting "Error:initialization from incompatible pointer type" error on line 'int *q = status;'.

Obviously, I'm missing something but has no clue...:(
Could someone please help me resolve this ?

void findwalls(int *p,int y,int x){
int status[y_count][x_count][4];
int *q = status;
for(int i = 0;i < (y_count * x_count * 4);i++)
*(q + i) = *(p + i);

Thanks!
Apr 8 '12 #1
1 10052
weaknessforcats
9,208 Expert Mod 8TB
You cannot create a multi-dimensional array when the size of the elements is unknown. In this case:

Expand|Select|Wrap|Line Numbers
  1. int status[y_count][x_count][4]; 
  2.  
status is an array of y_count elements but the size of the element is not known at compile time because x_count has no value. Therefore, you cannot create this array on the stack.

Then:
Expand|Select|Wrap|Line Numbers
  1. int *q = status; 
  2.  
doesn't work because status is not an int*. It is a pointer to a two-dimensional array of int.

I suggest you do this:

Expand|Select|Wrap|Line Numbers
  1. int* status = new int(y * x * 4);
Create an array of the correct number ints and initialize the array.

Later you can typecast status into another pointer that lets tou use the array as a multi-dinensional array.

Read this: http://bytes.com/topic/c/insights/77...rrays-revealed and pay special attention to the last example.
Apr 8 '12 #2

Sign in to post your reply or Sign up for a free account.

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...
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: Michael | last post by:
Hi all, why do I get a message: warning: passing arg 1 of `collectInput' from incompatible pointer type In 'main' have: char inputString; collectInput(&inputString);
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 {
13
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
5
by: plazzasele | last post by:
I want to register a new Person by using the set and get method. I am running my code on a program ( DEVc++), and when i compile the code i get this error message: assignment from incompatible...
6
by: suvas | last post by:
I have C code. On compliation it shows error, warning: assignment from incompatible pointer type Actually I wanted to evaluate integral then sum all the integrals. I would be glad if anyone could...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.