#include <iostream>
#include <stdlib.h>
#include <ctime>
class Date
{
private:
time_t t = time(NULL);
struct tm* ptime = localtime(&t);
int year = ptime->tm_year + 1900;
int month = ptime->tm_mon + 1;
int day = ptime->tm_mday;
public:
int getyear() {
return year;
}
int getmonth() {
return month;
}
int getday() {
return day;
}
};
int main(void) {
Date currtime;
char* pc1 = new char[11];
if (pc1 == NULL) {
printf("동적 메모리 할당에 실패했습니다.\n");
exit(1);
}
char* pc2 = new char[5];
if (pc2 == NULL) {
printf("동적 메모리 할당에 실패했습니다.\n");
exit(1);
}
int num, byear, bmonth, bday;
int curryear = currtime.getyear();
int currmonth = currtime.getmonth();
int currday = currtime.getday();
printf("학과명, 학번, 이름, 생년월일(생년 월 일)을 순서대로 입력하시오 > ");
scanf_s("%s %d %s %d %d %d", pc1, 11, &num, pc2, 5, &byear, &bmonth, &bday);
printf("%s %d %s님 %d년 %d월 %d일생 %d년 %d월 %d일 현재 나이는 %d세 입니다.", *pc1, num, *pc2, byear, bmonth, bday, curryear, currmonth, currday, curryear - byear + 1);
delete(pc1); delete(pc2);
return 0;
}
위의 프로그램을 실행하는데 계속해서 main함수의 scanf_s
줄에서
0x7AD01F4C(ucrtbased.dll)에(Project2.exe의) 처리되지 않은 예외가 있습니다.
0xC0000005: 0xFFFFFFCD 위치를 읽는 동안 액세스 위반이 발생했습니다.
라는 예외가 발생합니다. scanf_s
말고 scanf
를 써도, scanf_s
로 문자열을 입력받을 때에는 메모리 크기를 지정해줘야한다해서 메모리 크기도 지정했으나 예외가 계속 발생합니다. SDL검사같은 것도 비활성화시켜도봤고 이거저거 다해봤어요.. 당최 해결을 못하겠네요. Visual Studio 사용중입니다.