M
Mark
Hello
within studying ANSI C course I need to implement a simple function printing
current date and time. What I've written is not strictly standards
conformant, as I know they don't have time() function, but this is what I
came up with.
I compiled it with "gcc -std=c99 -pedantic -W -Wall -Wextra"
Please critisize this code, any suggestions on improvements are welcome.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
static size_t
showtime(char buf[], const size_t len)
{
time_t ticks;
int nchars;
ticks = time(NULL);
nchars = snprintf(buf, len, "%24s\n", ctime(&ticks));
return (size_t)nchars;
}
int main(void)
{
char buf[26];
memset(buf, '\0', sizeof buf);
if (showtime(buf, sizeof buf) == sizeof buf) {
printf("%s", buf);
}
return 0;
}
within studying ANSI C course I need to implement a simple function printing
current date and time. What I've written is not strictly standards
conformant, as I know they don't have time() function, but this is what I
came up with.
I compiled it with "gcc -std=c99 -pedantic -W -Wall -Wextra"
Please critisize this code, any suggestions on improvements are welcome.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
static size_t
showtime(char buf[], const size_t len)
{
time_t ticks;
int nchars;
ticks = time(NULL);
nchars = snprintf(buf, len, "%24s\n", ctime(&ticks));
return (size_t)nchars;
}
int main(void)
{
char buf[26];
memset(buf, '\0', sizeof buf);
if (showtime(buf, sizeof buf) == sizeof buf) {
printf("%s", buf);
}
return 0;
}