错误C4703和错误4716

时间:2016-04-28 16:28:50

标签: c

我正在编写一个输入日期格式的程序,并以不同的格式输出相同的日期。到目前为止,我只参与了该计划的前半部分,但我被困住了。我一直得到这两个错误。

*错误C4703:使用了潜在的未初始化的本地指针变量'month1'。

*错误C4716:'numDate'必须返回一个值。

#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()
{   

}

1 个答案:

答案 0 :(得分:3)

  

错误C4703:可能未初始化的本地指针变量&#39; month1&#39;使用

正如此消息所述,LoginButtonLoginButton loginButton = new LoginButton (new CGRect (48, 0, 218, 46)) { LoginBehavior = LoginBehavior.Native, ReadPermissions = readPermissions.ToArray (), }; loginButton.SetTitle("Test", UIControlState.Normal); 未初始化。通过更改

进行初始化
month1

类似

month < 1 || 12 < month

请注意,从字符串文字转换的指针已分配给char* month1; ,您无法修改字符串文字,因此使用const char* month1 = "(unknown month)"; 优于month1

  

错误C4716:&#39; numDate&#39;必须返回一个值。

const char*的返回类型为char*,因此该函数必须返回值numDate。如果您不想返回任何值,请将返回类型更改为int。请注意,您必须同时更改声明和定义。