?
Solved

I am lost with the C time tm struct

Posted on 2014-09-30
3
Medium Priority
?
231 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
2 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

612 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