Solved

I am lost with the C time tm struct

Posted on 2014-09-30
3
199 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
3 Comments
 
LVL 30

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now