I'm trying to print a date from a string like "01/01/01" and get something like "Monday First January 2001.
I found something with the man of ctime but really don't get it how to use it.
Any help ?
Thanks,
One way to check this: Just initialize the variable and then take input. int date = 0, month = 0, year = 0; scanf("%d/%d/%d", &date, &month, &year); Now, if you give 10-12-2016 as input, you will get 10-0-0 as output.
Explanation: In the above program, variable c is assigned the character 'a'. In the printf statement when %u is used to print the value of the char c, then the ASCII value of 'a' is printed. Case 2: Print float value using %u.
The f in printf stands for formatted, its used for printing with formatted output.
%s refers to a string %d refers to an integer %c refers to a character. Therefore: %s%d%s%c\n prints the string "The first character in sting ", %d prints i, %s prints " is ", and %c prints str[0].
You can use strptime
to convert your string date to struct tm
struct tm tm;
strptime("01/26/12", "%m/%d/%y", &tm);
And then print struct tm
in the appropriate date format with strftime
char str_date[256];
strftime(str_date, sizeof(str_date), "%A, %d %B %Y", &tm);
printf("%s\n", str_date);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With