C计划 - "异常抛出0x0FFC0F18(ucrtbased.dll)"调试时收到此错误

时间:2016-01-08 08:37:14

标签: c

我尝试逐行调试代码行,并且知道它在行上显示错误" if(strcmp(takein.year,takein.year2)== 0)"。

Error Image - click here

请检查上面的链接。 我用红框标记了这一行。 不知道为什么会出现这个错误。

#include<stdio.h>
#include<stdlib.h>
#include<process.h>

//STRUCTURE
struct date_struct
{
int day;
int month;
int year;
int day2;
int month2;
int year2;

};

//USER-DEFINED FUNCTION
float input(struct date_struct takein);
char tarik(struct date_struct printer);
void header();
//STRUCTURE-VARIABLES
struct date_struct date = { 0,0,0 };

void header()
{
printf("*-*-*-*DATE_STRUCT*-*-*-*");
printf("\n\n");
}

//PROGRAM STARTS HERE
main()
{

//HEADING
header();

//FUCNTION CALL-OUT
input(date);

//TERMINAL_PAUSE
system("pause");
}

float input(struct date_struct takein)
{
printf("Enter the Date(1) : \n");

printf("Day : ");
scanf_s("%d", &takein.day);
printf("\n");

printf("Month : ");
scanf_s("%d", &takein.month);
printf("\n");

printf("Year : ");
scanf_s("%d", &takein.year);

printf("\n");
printf("\n");

printf("Enter the Date-(2) : \n");

printf("Day : ");
scanf_s("%d", &takein.day2);
printf("\n");

printf("Month : ");
scanf_s("%d", &takein.month2);
printf("\n");

printf("Year : ");
scanf_s("%d", &takein.year2);
printf("\n");

tarik(takein);

if (strcmp(takein.year, takein.year2) == 0)
{
    if (strcmp(takein.month, takein.month2) == 0)
    {
        if (strcmp(takein.year, takein.year2) == 0)
        {
            return(0);
        }
        else
            return(1);
    }
    else
        return(1);
}
else
    return(1);

}

char tarik(struct date_struct printer)
{
switch (printer.month)
{

case 1:
    printf("Date(1) : January %d, %d\n\n", printer.day, printer.year);
    break;

case 2:
    printf("Date(1) : February %d, %d\n\n", printer.day, printer.year);
    break;

case 3:
    printf("Date(1) : March %d, %d\n\n", printer.day, printer.year);
    break;

case 4:
    printf("Date(1) : April %d, %d\n\n", printer.day, printer.year);
    break;

case 5:
    printf("Date(1) : May %d, %d\n\n", printer.day, printer.year);
    break;

case 6:
    printf("Date(1) : June %d, %d\n\n", printer.day, printer.year);
    break;

case 7:
    printf("Date(1) : July %d, %d\n\n", printer.day, printer.year);
    break;

case 8:
    printf("Date(1) : August %d, %d\n\n", printer.day, printer.year);
    break;

case 9:
    printf("Date(1) : September %d, %d\n\n", printer.day, printer.year);
    break;

case 10:
    printf("Date(1) : Octomber %d, %d\n\n", printer.day, printer.year);
    break;

case 11:
    printf("Date(1) : November %d, %d\n\n", printer.day, printer.year);
    break;

case 12:
    printf("Date(1) : Devember %d, %d\n\n", printer.day, printer.year);
    break;
}

switch (printer.month2)
{

case 1:
    printf("Date(2) : January %d, %d\n\n", printer.day2, printer.year2);
    break;

case 2:
    printf("Date(2) : February %d, %d\n\n", printer.day2, printer.year2);
    break;

case 3:
    printf("Date(2) : March %d, %d\n\n", printer.day2, printer.year2);
    break;

case 4:
    printf("Date(2) : April %d, %d\n\n", printer.day2, printer.year2);
    break;

case 5:
    printf("Date(2) : May %d, %d\n\n", printer.day2, printer.year2);
    break;

case 6:
    printf("Date(2) : June %d, %d\n\n", printer.day2, printer.year2);
    break;

case 7:
    printf("Date(2) : July %d, %d\n\n", printer.day2, printer.year2);
    break;

case 8:
    printf("Date(2) : August %d, %d\n\n", printer.day2, printer.year2);
    break;

case 9:
    printf("Date(2) : September %d, %d\n\n", printer.day2, printer.year2);
    break;

case 10:
    printf("Date(2) : Octomber %d, %d\n\n", printer.day2, printer.year2);
    break;

case 11:
    printf("Date(2) : November %d, %d\n\n", printer.day2, printer.year2);
    break;

case 12:
    printf("Date(2) : Devember %d, %d\n\n", printer.day2, printer.year2);
    break;
}

return;
}

3 个答案:

答案 0 :(得分:3)

strcmp(takein.year, takein.year2)错误,takein.yeartakein.year2的类型为int,而非char*

更换

strcmp(takein.year, takein.year2)

通过

takein.year == takein.year2

应该做的工作,但可能还有其他问题。

答案 1 :(得分:1)

strcmp(takein.year, takein.year2)  

比较地址takein.yearteakein.year2的字符串存储。

我们在takein.yearteakein.year2中有什么?

这些只是普通整数和不是地址。这里strcmp试图访问其分配的进程内存空间之外的内存位置以及异常的原因。

使用==来比较int

使用strcmp比较字符串

还有什么是scanf_s("%d", &takein.year2);

我不相信scanf_s是标准的库函数。此代码是否已成功编译并获取链接?

此外,如果您正在使用字符串库函数,那么请包含<string.h>,但很可能默认链接库包含大多数常用函数的函数定义。 (例如Linux中的libc

答案 2 :(得分:1)

你已经得到了研究员的全面回答,我只想为你的代码添加一些改进:

botle