473,405 Members | 2,415 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,405 software developers and data experts.

Warning: Initialization Makes Integer From Pointer Without A Cast

Hello everyone,

I am somewhat new to C programming (I started last year) and I'm fairly good at it so far...that is, until I've recently started working with structures.

In my current program, I'm simply trying to initialize a simple array of structures that will be the test template for other similar programs I plan on using in the future. The program is as follows:

================================================== =======
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.  
  6.         int time, closest;
  7.  
  8.         struct flight
  9.         {
  10.                 int depart[FLIGHTS];
  11.                 int arrive[FLIGHTS];
  12.                 char *attendant;
  13.         };
  14.  
  15.         struct flight schedule[] =
  16.         {{800, 1016, "Jason Mackenzie"},
  17.           {943, 1152, "Valerie Woods"},
  18.           {1119, 1331, "Antonio Vasquez"},
  19.           {1247, 1500, "Natalie McIver"},                   
  20.           {1400, 1608, "Scott Curtis"},
  21.           {1545, 1755, "Yvonne Vogelar"},
  22.           {1900, 2120, "Mitch Matthews"},
  23.           {2145, 2358, "Marcie Maddox"}};
  24.  
  25.         printf("%d\n", schedule[0].arrive[0]);
  26.  
  27.         return 0;
  28. }
  29.  
================================================== =======

For each line where I'm trying to initialize each index of the schedule array, the
compiler gives me a warning and I can't figure out why.

To test to see if my code was correct or not, I used a simple printf( ) statement, and all I got for the output was zero, so I'm obviously doing something wrong here. Can anyone help? I'd really appreciate it--thanks!

RICH
Mar 8 '09 #1
3 16565
donbock
2,426 Expert 2GB
@nexusdarkblue
The 'departs' and 'arrive' structure fields are arrays. You need to properly delimit array initializers:
Expand|Select|Wrap|Line Numbers
  1.         struct flight schedule[] = {
  2.             { {800}, {1016}, "Jason Mackenzie"},
  3.             { {943}, {1152}, "Valerie Woods"},
  4.             { {1119}, {1331}, "Antonio Vasquez"},
  5.             { {1247}, {1500}, "Natalie McIver"},                   
  6.             { {1400}, {1608}, "Scott Curtis"},
  7.             { {1545}, {1755}, "Yvonne Vogelar"},
  8.             { {1900}, {2120}, "Mitch Matthews"},
  9.             { {2145}, {2358}, "Marcie Maddox"}
  10.         };
Suppose you want one of these initializers to set more than the first element in the 'departs' array:
Expand|Select|Wrap|Line Numbers
  1.             { {943, 1159, 1530}, {1152}, "Valerie Woods"},
One last observation, the 'attendant' field should be defined as 'const char * const' unless you intend to change the 'attendant' strings on the fly.
Mar 8 '09 #2
Savage
1,764 Expert 1GB
@nexusdarkblue
You are trying to initialize a array with a single integer, interesting thing is that you get only a warning, this is a compile time error on all the compilers i know.

You need to add an extra pair of curly brackets around the array intialization something like this:

Expand|Select|Wrap|Line Numbers
  1.     struct flight schedule[] =
  2.     {
  3.       {{800}, {1016}, "Jason Mackenzie"},
  4.       {{943}, {1152}, "Valerie Woods"},
  5.       {{1119}, {1331}, "Antonio Vasquez"},
  6.       {{1247}, {1500}, "Natalie McIver"},
  7.       {{1400}, {1608}, "Scott Curtis"},
  8.       {{1545}, {1755}, "Yvonne Vogelar"},
  9.       {{1900}, {2120}, "Mitch Matthews"},
  10.       {{2145}, {2358}, "Marcie Maddox"}
  11.     };
EDIT:Guess I'm a bit too late,didn't see don's post coming ^^
Mar 8 '09 #3
Ahhh, the curly braces! Thanks to you both donbock and Savage--my code works like a charm now! (Can't believe I forgot those curly braces--it's so simple! :-)

RICH
Mar 8 '09 #4

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

Similar topics

27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
4
by: Dawn Minnis | last post by:
Hi When I compile my files I get the following: driver.c: In function `main': driver.c:49: warning: assignment makes integer from pointer without a cast driver.c:50: warning: assignment...
16
by: jose_luis_fdez_diaz_news | last post by:
Hi, If I don't include <libgen.h> I get then warnig below in regcmp call: warning: improper pointer/integer combination: op "=" but if I include it the warning is not shown, but them program...
2
by: francescomoi | last post by:
Hi. I'm trying to compile this piece of source: ------------------------------------------- int id; while(row1 = mysql_fetch_row(rs1)) { id = atoi((int)row1);...
29
by: junky_fellow | last post by:
Consider the following piece of code: struct junk { int i_val; int i_val1; char c_val; }; int main(void) {
4
by: metalinc | last post by:
hi...im new to C programming...need help...tried to run this code but got this error fork.c: In function ‘parse’: fork.c:44: warning: comparison between pointer and integer fork.c:51: warning:...
3
by: mrmattborja | last post by:
Hello, Here is a program I'm playing around with for fun in the process of learning C. The objective is to create a function filesize() and call it from within the main() section to retrieve the...
7
by: llothar | last post by:
When i use -W4 on visual c 7.0 i get warning C4054 translator1.c(1703) : warning C4054: 'type cast' : from function pointer 'void * (__cdecl *)(se_agent *)' to data pointer 'void *'...
10
drhowarddrfine
by: drhowarddrfine | last post by:
warning: assignment makes pointer from integer without a cast I get that when I compile a C file where the function is defined as this: char **getvars() and the calling function has this...
1
by: woods1313drew | last post by:
The following code in c+ gives me the warning assignment makes integer from pointer without a cast. destination is set as char destination to limit the input string to 10 characters. name is an...
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: 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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
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,...

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.