Ich schreibe ein Programm, das ein Datumsformat eingibt und eine Ausgabe desselben Datums in einem anderen Format hat. Bis jetzt habe ich nur an der ersten Hälfte des Programms gearbeitet, aber ich stecke fest. Ich bekomme immer diese 2 Fehler.Fehler C4703 und Fehler 4716
* Fehler C4703: Potenziell nicht initialisierte lokale Zeigervariable 'month1' verwendet.
* Fehler C4716: 'numDate' muss einen Wert zurückgeben.
#include<stdio.h>
int numDate();
void wrdDate();
int main()
{
int a;
printf("Write a date to have it converted to an alternate format. You can write your date\n");
printf("in one of two ways. Either in purely numeric form, ex(09/18/2016), or a complete written\n");
printf("out form, ex(September 18, 2016). Enter one of those formats and receive the other one in return.");
printf("If you wish enter a 09/18/2016 format, enter 1\n");
printf("If you wish to enter a September 18, 2016 format, enter 2.\n");
scanf_s("%d", &a);
if (a == 1)
{
numDate();
}
if (a == 2)
{
wrdDate();
}
}
int numDate()
{
int day, month, year;
int day1;
char* month1;
int year1;
printf("Enter date (dd/mm/yy): ");
scanf_s("%d/%d/%d", &month, &day, &year);
day1 = day;
year1 = year;
if (day < 0)
{
if (month == 1)
month1 = "January";
else if (month == 2)
month1 = "February";
else if (month == 3)
month1 = "March";
else if (month == 4)
month1 = "April";
else if (month == 5)
month1 = "May";
else if (month == 6)
month1 = "June";
else if (month == 7)
month1 = "July";
else if (month == 8)
month1 = "August";
else if (month == 9)
month1 = "September";
else if (month == 10)
month1 = "October";
else if (month == 11)
month1 = "November";
else if (month == 12)
month1 = "December";
}
day1 = day;
year1 = year;
printf("%s %d, %d,", month1, day1, year1); //It says Error 4703 is happening here
}
int wrdDate()
{
}
Hinweis: 'month == 01' und' month == 1' haben nach der Erstellung genau die gleiche Bedeutung. Also als 'month == 02' und' month == 2' usw. – MikeCAT
''numDate' muss einen Wert zurückgeben, sollte ziemlich offensichtlich sein. Sie haben dem Compiler gesagt, dass 'numDate' ein' int' zurückliefern wird, aber niemals etwas zurückgibt. – Michael
Warum nicht ein Array (in diesem Fall vorzuziehen) oder eine 'switch' Anweisung anstelle der vielen' if' Anweisungen verwenden? – MikeCAT