Solved

I am lost with the C time tm struct

Posted on 2014-09-30
3
217 Views
Last Modified: 2014-09-30
I am transfering old libs from bcc32 to tcc. I am blocked by this one in the marked line. Tcc says "structure or union expected".

Question: what is wrong with tcc.

The rest of the function is not debugged yet, tcc seems to proceed one problem at a time.
Thank you for your help.

long m_time(long tim0)
{
long   tx;
int    k;
int    mod;
int    mois, an;
struct tm * t;
time_t timer;
char   fig[10];
int    i;

   time(&timer);
   t=localtime(&timer);
   sprintf(mc_eurodate,"%02d/%02d/%02d %02d:%02d:%02d",
           t.tm_mday,t.tm_mon,t.tm_year+1900,t.tm_hour,t.tm_min,t.tm_sec);    <=== error line.
   sprintf(mc_univdate,"%04d/%02d/%02d %02d:%02d:%02d",
           t.tm_year+1900,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec);
   sprintf(mc_gdh     ,"%04d%02d%02d%02d%02d%02d",
           t.tm_year+1900,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec);
   sprintf(mc_soa     ,"%04d%02d%02d%02d",
           t.tm_year+1900,t.tm_mon,t.tm_mday,t.tm_hour);
   sprintf(mc_hour    ,"%02d", t.tm_hour );
   sprintf(mc_zipdate ,"%02d%02d%04d", t.tm_mon,t.tm_mday,t.tm_year+1900);
   sprintf(curr_date,"%-8.8s",mc_gdh);
   sprintf(mc_collmois,"%04d%02d",t.tm_year+1900,t.tm_mon);
   mois=d.da_mon;
   an  =t.tm_year+1900&100;
   memmove(mc_collmois,&mc_collmois[2],5);
   sprintf(mc_collweek,"%04ld",(timer+86400L*(t.tm_day+2L)+
           3600L*t.tm_hour)/604800L-524L);
   sprintf(mc_collday,"%0ld",(timer/86400L)-3653L);
   if (strlen(mc_collday)==5) memmove(mc_collday,&mc_collday[1],5);
  
   for (i=0;i<6;i++)
   {
      sprintf(mc_mois[0],"%02d%02d",an, mois--);
      if (mois==0) {mois=12; an--;}
   }

   tx=timer-315360000L;
   memset(fig,0,10);
   memset(fig,' ',9);
   k=7;
   while(1)
   {
      mod=tx%34;
      if      (mod<8)   fig[k]=mod+'A';
      else if (mod<13)  fig[k]=mod+'A'+1;
      else if (mod<24)  fig[k]=mod+'A'+2;
      else              fig[k]=mod+'0'-24;
      k--;
      if ((tx=tx/34)==0L) break;
   }
   m_head(fig);
   m_short(fig);
   sprintf(mc_ref,"%s",fig);

   mois=t.tm_mon;
   an  =t.tm_year+1900;
   mois=mois-7;
   if (mois<1) {mois=12+mois; an--;}
   sprintf(mc_six,"%04d%02d",an,mois); 
   mois=t.tm_mon;
   an  =t.tm_year+1900;
   mois=mois-12;
   if (mois<1) {mois=12+mois;an--;}
   sprintf(mc_eleven,"%04d%02d",an,mois); 
   return(timer+tim0);
}

Open in new window

0
Comment
Question by:versailles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 40352200
Hi versailles,

the problem IMO is you use '.' instead of '->' to access members of 't' (which is a pointer).

So you should replace all statements like ' t.tm_mda' with ' t->tm_mda'.

Hope that helps,

ZOPPO
0
 

Author Closing Comment

by:versailles
ID: 40352307
This does help !
Silly of mine. I am somewhat rusty with my C. I change compiler because BCC32 is out of commission now.
Thank you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question