Hi,
I have had a look in the FAQ but cannot see anything related, of course that
doesn't mean it's not there.
In any case:
I have the following:
void function(){
struct tm *time2;
time_t date1;
......stuff.... ..
time2 = localtime(&date 2);
year = time2.tm_year;
}
why does the year= time2.tm_year; give me an error that says "request for
member tm_year in somthing not a structure"?
If I replace this line with printf("%s", asctime(time2)) ; I get a print of
the date I have set in the structure, so I know the structure has valid
data.
Can anyone help me out here?
Regards
Michael 3 2157
Michael wrote: Hi,
I have had a look in the FAQ but cannot see anything related, of course that doesn't mean it's not there. In any case:
I have the following:
void function(){ struct tm *time2; time_t date1;
.....stuff..... .
time2 = localtime(&date 2); year = time2.tm_year; }
why does the year= time2.tm_year; give me an error that says "request for member tm_year in somthing not a structure"?
time2 is a pointer to struct tm.
You want time2->tm_year.
--
Ian Collins.
"Michael" <mi*********@ya hoo.com> writes: Hi,
I have had a look in the FAQ but cannot see anything related, of course that doesn't mean it's not there. In any case:
I have the following:
void function(){ struct tm *time2;
So, time2 is a pointer to a struct tm.
time_t date1;
.....stuff..... .
time2 = localtime(&date 2);
localtime can return null. You should test for that just to make sure
there are no problems. You'll have to dereference the pointer next, as
you'll see, and you can't do that if the pointer is null.
I'm not sure if this is in the standard but the pointer returned by
localtime points to a struct tm that's declared static, so make sure
you don't mess things up my interspersing calls to localtime, with
other calls to localtime, gmtime and checking the values returned like
this:
t1=localtime(.. .);
year=t1.tm_year ;
t2=localtime(.. .);
/* after this call t1 and t2 point to the same thing */
month1=t1->tm_mon+1;
month2=t2->tm_mon+1;
/* month1==month2 */
year = time2.tm_year;
Remember, time2 is a pointer to a struct tm. tm_year is a member of a
struct tm structure. time2 is a pointer that's why it says you're
requesting tm_year in something not a structure because time2 is
a pointer to the structure you want. You can dereference the pointer,
so you could use either of these:
1. year = (*time2).tm_yea r;
2. year = time2->tm_year;
}
why does the year= time2.tm_year; give me an error that says "request for member tm_year in somthing not a structure"?
If I replace this line with printf("%s", asctime(time2)) ; I get a print of the date I have set in the structure, so I know the structure has valid data.
That's because asctime requires a pointer to struct tm and not just a
struct tm.
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Thanks heaps guys
"Nelu" <sp*******@gmai l.com> wrote in message
news:b1******** *****@otaku.fre eshell.org... "Michael" <mi*********@ya hoo.com> writes:
Hi,
I have had a look in the FAQ but cannot see anything related, of course that doesn't mean it's not there. In any case:
I have the following:
void function(){ struct tm *time2; So, time2 is a pointer to a struct tm.
time_t date1;
.....stuff..... .
time2 = localtime(&date 2); localtime can return null. You should test for that just to make sure there are no problems. You'll have to dereference the pointer next, as you'll see, and you can't do that if the pointer is null. I'm not sure if this is in the standard but the pointer returned by localtime points to a struct tm that's declared static, so make sure you don't mess things up my interspersing calls to localtime, with other calls to localtime, gmtime and checking the values returned like this:
t1=localtime(.. .); year=t1.tm_year ; t2=localtime(.. .); /* after this call t1 and t2 point to the same thing */ month1=t1->tm_mon+1; month2=t2->tm_mon+1; /* month1==month2 */
year = time2.tm_year; Remember, time2 is a pointer to a struct tm. tm_year is a member of a struct tm structure. time2 is a pointer that's why it says you're requesting tm_year in something not a structure because time2 is a pointer to the structure you want. You can dereference the pointer, so you could use either of these: 1. year = (*time2).tm_yea r; 2. year = time2->tm_year; }
why does the year= time2.tm_year; give me an error that says "request for member tm_year in somthing not a structure"?
If I replace this line with printf("%s", asctime(time2)) ; I get a print of the date I have set in the structure, so I know the structure has valid data. That's because asctime requires a pointer to struct tm and not just a struct tm.
-- Ioan - Ciprian Tandau tandau _at_ freeshell _dot_ org (hope it's not too late) (... and that it still works...) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shelly |
last post by:
Here is a question that is probably very easy but that I don't know how to
do .
I have a web site www.aaa.net. A directory structure has been created for
me on the server as and it appears to me as /var/www/html. That is where
all my code is placed.
I want to have another site, www.aaa.org. I want the directory structure
for the html and php for this to be under the www.aaa.net directory tree in
a subdirectory org ...
|
by: PatchFactory Support |
last post by:
Description:
Professional and easy-to-use patch building environment that can help
you to create instant patch packages for software and file updating.
Generated patch packages are small size self-extracting executable
update programs in a famous installer style with adjustable
user-friendly interface and multilingual support.
Enhanced with features like easy-to-use interface including a Wizard
mode, powerful patch engine, integrated...
|
by: Maximus |
last post by:
Hi,
Ok my problem is hard to explain... I'm making a directdraw based program
and of course maps. I can put texture on my map but I want to save those
information in a structure with a x, y and a texture variable assigned to
that coord in order to recreate the map over and over again. Think about it,
how would you make that structure or anything else that would do the job...?
First I came with a very stupid conclusion:
struct DDMAP
{...
|
by: andy.dreistadt |
last post by:
Hi all,
I came across another problem that is probably pretty easy but, again,
due to my rusty-ness with C, I'm a little stumped.
I have a struct that looks like this:
/* Instrument Data structure */
struct instrument_info
{
|
by: Ryan Smith |
last post by:
I have a code behind ASP.NET app and on one page I populate a user defined
structure from a database. I would like to pass that populated structure to
another page so I do not need to perform multiple database calls. Is this
possible and if so how?
Ryan
| |
by: Qwert |
last post by:
Hello,
is it correct that if a type (System.Type) is a value (.IsValueType=True)
and not primitive (.IsPrimitive=False), that type is a structure?
Thanks.
|
by: taddub |
last post by:
Hi All
I need to tell a colleague how to get the structure (table name +
column names + primary key + index etc) of each table in a SQL 6.5
database.
I can't access the server as it is on another site several 100's of
miles away, so I need step by step destructions on how to do it. I'm
not that hot at SQL and my colleague is even worse so really clear
instructions would be appreciated.
|
by: Michael |
last post by:
Hi,
In some code in my header file I have:
typedef struct{
int book_id;
char title;
char author;
int year;
int price;
|
by: jehugaleahsa |
last post by:
Hello:
We are running into an issue. Whenever our users save using either the
save key or a BindingNavigator, whatever control is in focus won't be
updated. Our users are getting confused when they are asked whether
they want to save their changes.
Is there a way to force the the control changes to be accepted prior
to saving? Is there an easy way to add this to all of our code?
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |