Last active
August 29, 2015 14:01
-
-
Save mundry/b80a396e38d7a2322311 to your computer and use it in GitHub Desktop.
C program to print the current local time to standard output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local-time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <time.h> | |
#define TIME_STRING_LENGTH 23 | |
int main(void) { | |
time_t currentTime; | |
char currTimeStr[TIME_STRING_LENGTH]; | |
struct tm* tmInfo; | |
/* Obtain current time as seconds elapsed since the Epoch. */ | |
time(¤tTime); | |
tmInfo = localtime(¤tTime); | |
strftime(currTimeStr, TIME_STRING_LENGTH, "[%Y-%m-%d %H:%M:%S] ", tmInfo); | |
printf("%s\n", currTimeStr); | |
printf("%ld\n", strlen(currTimeStr)); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TARGET := local-time | |
$(TARGET): local-time.c | |
gcc -Werror -Wall -O2 -o $@ $< | |
run: $(TARGET) | |
@./$(TARGET) | |
clean: | |
$(RM) $(TARGET) | |
.PHONY: run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment