K
kuoyang.hu
I have wrote a C program and wish the second with 2 digitals, how to do?
Sample as follow:
0 -> 00, 1 -> 01...9->09.
==============================
My program as follow:
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t mytime;
mytime = time(NULL);
printf(ctime(&mytime));
struct tm *t;
time_t now;
now = time ( NULL );
t = localtime ( &now );
int MySec = t->tm_sec;
char *Init = "data";
char buffer [30];
char End [256];
printf ( "The New %02d:%02d:%02d\n", t->tm_hour, t->tm_min, t->tm_sec );
strcpy (End, Init);
printf("Data = %s\n",End);
itoa(MySec,buffer,10);
strcat (End,buffer);
printf("Data = %s\n",End);
return 0;
}
==================
Executed on Windows with DOS command
D:\tcc>getSecond.exe
Wed Nov 27 17:05:01 2013
The New 17:5:01
Data = data
Data = data1 <- I want the format is "Data = data1"
Regard & thanks,
Kuoyang
Sample as follow:
0 -> 00, 1 -> 01...9->09.
==============================
My program as follow:
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t mytime;
mytime = time(NULL);
printf(ctime(&mytime));
struct tm *t;
time_t now;
now = time ( NULL );
t = localtime ( &now );
int MySec = t->tm_sec;
char *Init = "data";
char buffer [30];
char End [256];
printf ( "The New %02d:%02d:%02d\n", t->tm_hour, t->tm_min, t->tm_sec );
strcpy (End, Init);
printf("Data = %s\n",End);
itoa(MySec,buffer,10);
strcat (End,buffer);
printf("Data = %s\n",End);
return 0;
}
==================
Executed on Windows with DOS command
D:\tcc>getSecond.exe
Wed Nov 27 17:05:01 2013
The New 17:5:01
Data = data
Data = data1 <- I want the format is "Data = data1"
Regard & thanks,
Kuoyang