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:
=============== =============== =============== ============ -
#include <stdio.h>
-
-
int main(int argc, char *argv[])
-
{
-
-
int time, closest;
-
-
struct flight
-
{
-
int depart[FLIGHTS];
-
int arrive[FLIGHTS];
-
char *attendant;
-
};
-
-
struct flight schedule[] =
-
{{800, 1016, "Jason Mackenzie"},
-
{943, 1152, "Valerie Woods"},
-
{1119, 1331, "Antonio Vasquez"},
-
{1247, 1500, "Natalie McIver"},
-
{1400, 1608, "Scott Curtis"},
-
{1545, 1755, "Yvonne Vogelar"},
-
{1900, 2120, "Mitch Matthews"},
-
{2145, 2358, "Marcie Maddox"}};
-
-
printf("%d\n", schedule[0].arrive[0]);
-
-
return 0;
-
}
-
=============== =============== =============== ============
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
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: - struct flight schedule[] = {
-
{ {800}, {1016}, "Jason Mackenzie"},
-
{ {943}, {1152}, "Valerie Woods"},
-
{ {1119}, {1331}, "Antonio Vasquez"},
-
{ {1247}, {1500}, "Natalie McIver"},
-
{ {1400}, {1608}, "Scott Curtis"},
-
{ {1545}, {1755}, "Yvonne Vogelar"},
-
{ {1900}, {2120}, "Mitch Matthews"},
-
{ {2145}, {2358}, "Marcie Maddox"}
-
};
Suppose you want one of these initializers to set more than the first element in the 'departs' array: - { {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.
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: - struct flight schedule[] =
-
{
-
{{800}, {1016}, "Jason Mackenzie"},
-
{{943}, {1152}, "Valerie Woods"},
-
{{1119}, {1331}, "Antonio Vasquez"},
-
{{1247}, {1500}, "Natalie McIver"},
-
{{1400}, {1608}, "Scott Curtis"},
-
{{1545}, {1755}, "Yvonne Vogelar"},
-
{{1900}, {2120}, "Mitch Matthews"},
-
{{2145}, {2358}, "Marcie Maddox"}
-
};
EDIT:Guess I'm a bit too late,didn't see don's post coming ^^
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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 ?
|
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);
-----------------------------------
|
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)
{
| |
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':...
|
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;
|
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...
|
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();
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |