A
arnuld
I wonder why warnings are coming. I following the man page exactly:
/* Print time without a newline */
#include <stdio.h>
#include <string.h>
#include <time.h>
void print_time(void);
int main(void)
{
print_time();
return 0;
}
void print_time(void)
{
char arrt[100] = {0};
time_t now = time(NULL);
char* p;
if(NULL == ctime_r(&now, arrt))
{
printf("Failed to get time\n");
}
else
{
for(p = arrt; *p && (*p != '\n'); ++p)
{
printf("%c", *p);
}
printf(" <--- this is the time\n");
}
}
====================== OUTPUT =========================
~/programs/C $ gcc -ansi -pedantic -Wall -Wextra time.c
time.c: In function ‘print_time’:
time.c:21: warning: implicit declaration of function ‘ctime_r’
time.c:21: warning: comparison between pointer and integer
~/programs/C $ ./a.out
Tue Apr 10 19:37:41 2012 <--- this is the time
~/programs/C $
/* Print time without a newline */
#include <stdio.h>
#include <string.h>
#include <time.h>
void print_time(void);
int main(void)
{
print_time();
return 0;
}
void print_time(void)
{
char arrt[100] = {0};
time_t now = time(NULL);
char* p;
if(NULL == ctime_r(&now, arrt))
{
printf("Failed to get time\n");
}
else
{
for(p = arrt; *p && (*p != '\n'); ++p)
{
printf("%c", *p);
}
printf(" <--- this is the time\n");
}
}
====================== OUTPUT =========================
~/programs/C $ gcc -ansi -pedantic -Wall -Wextra time.c
time.c: In function ‘print_time’:
time.c:21: warning: implicit declaration of function ‘ctime_r’
time.c:21: warning: comparison between pointer and integer
~/programs/C $ ./a.out
Tue Apr 10 19:37:41 2012 <--- this is the time
~/programs/C $