473,569 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning: Initialization Makes Integer From Pointer Without A Cast

6 New Member
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 16572
donbock
2,426 Recognized Expert Top Contributor
@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 Recognized Expert Top Contributor
@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
nexusdarkblue
6 New Member
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
4725
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: assignment makes pointer from integer without a cast ================================================================== when the following piece of...
4
36168
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 makes integer from pointer without a cast driver.c:51: warning: assignment makes integer from pointer without a
16
5818
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 compiles fine. What is the warning shown ?
2
14308
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
2488
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
6527
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: assignment makes integer from pointer without a cast fork.c:61: warning: comparison between pointer and integer /tmp/cciECfg4.o: In function `main':...
3
17139
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 size in bytes of a file that I give it. #include <stdio.h> long filesize(f) { FILE *fp;
7
5252
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 *' translator1.c(1703) : warning C4152: nonstandard extension, function/ data pointer conversion in expression whenever i cast a function pointer to a void* or...
10
9479
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 declared: char **s; and I write: s=getvars();
1
3758
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 array of ten places char name iv looked in several books but cant find an references to integer pointer errors. Could someone tell me what i am doing...
0
7703
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
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6287
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
5514
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
3657
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...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.