1
Create a program that receives the date in numeral and then return it in full.
I tried to do a few times, but I ended up merging my code with one I found from a forum and came out like this:
#include <stdio.h>
#include <stdlib.h>
void Date(int day, int month, int year);
int main(void){
int day, month, year;
printf("\nDay(1-31): ");
scanf("%i", &day);
//limpa o buffer de entrada.
getchar();
printf("\nMonth(1-12): ");
scanf("%i", &month);
//limpa o buffer de entrada.
getchar();
printf("\nYear(xxxx): ");
scanf("%i", &year);
Date(day, month, year);
return 0;
}
void Date(int day, int month, int year){
const char* months[] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"Setember", "October", "November", "Dezember"};
system ("clear"); //gnu-linux
printf("The Date is: %s %dth, %d\n", months[month - 1], day , year);
}
I therefore had two doubts about the end of this code:
1 - why [Month - 1]?
2 - why the vector has no value inside to allocate?
3 - why it is necessary to declare const
in the char variable?