I have a program that asks for the day, month, and year and returns a formatted version. For example, if I entered what the program currently checks for (28 for the day, 7 for the month, and 2010 for the year), it will print July 28, 2010. However, I am getting a segmentation fault which gdb is telling me is on line 25, which I have highlighted. Can anyone help with this issue?
Code:
#include <stdio.h>
#include <string.h>
/* Prototypes */
void Get_New_Day(int *x, char *y);
void Get_New_Month(int *x, char *y);
int main() {
int day;
int month;
int year;
char new_day[100];
char new_month[100];
char new_string[100];
printf("\nEnter the day: ");
scanf("%d", &day);
printf("\nEnter the month: ");
scanf("%d", &month);
printf("\nEnter the year: ");
scanf("%d", &year);
Get_New_Day(&day, new_day);
Get_New_Month(&month, new_month);
printf("\nIt is %s %s, %d.\n\n", new_month, new_day, year);
return 0;
}
void Get_New_Day(int *x, char *y) {
switch (*x) {
case 28:
strcpy(*y, "28th");
break;
default:
strcpy(*y, "null");
break;
}
}
void Get_New_Month(int *x, char *y) {
switch (*x) {
case 7:
strcpy(*y, "March");
break;
default:
strcpy(*y, "NULL");
break;
}
}