비주얼 스튜디오 C++에서 인터럽트 작업 :C/C++ - 나는 컴퓨터 과학 학생입니다 최근에이 코드를 내놓았다 웹에서 검색 몇 후 C. 에서 인터럽트를 사용하는 방법을 배웠습니다
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
#define INTR 0x1c
#define gotoxy(x,y) printf("\033[%d;%dH", (x), (y))
//#define clear() printf("\033[H\033[J");
/*
//positioning
void gotoxy(int x, int y)
{
printf("%c[%d;%df",0x1B,y,x);
}
*/
void interrupt handler(__CPPARGS);
void interrupt (*oldhandler)(__CPPARGS);
int countS = 0;
int s = 0;
int m = 0;
int ms = 0;
int l = 0;
int flag = 0;
int main(void)
{
clrscr();
printf("%02d:%02d:%02d",m,s,ms);
oldhandler = getvect(INTR);
setvect(INTR, handler);
char c;
while(1)
{
c = getch();
switch(c){
case 'e':
goto exit_loop;
break;
case ' ':
flag = 1-flag;
break;
case 'r':
flag = s = m = ms = l = 0;
clrscr();
printf("%02d:%02d:%02d",m,s,ms);
break;
case 'l':
gotoxy(++l,0);
printf("%02d:%02d:%02d",m,s,ms);
break;
}
}
exit_loop:;
setvect(INTR, oldhandler);
return 0;
}
void interrupt handler(__CPPARGS)
{
if(flag == 1){
countS++;
ms += 55;
if(countS == 18)
{
countS = ms = 0;
s++;
if(s==60)
{
m++;
s = 0;
}
}
gotoxy(0,0);
printf("%02d:%02d:%02d",m,s,ms);
}
}
이 코드는 C 콘솔 응용 프로그램에서 일종의 스톱워치이며 역사적인 Turbo C++에서 완벽하게 작동합니다. Visual Studio에서 2013을 사용하여 IDE를 변경했는데 Visual C++ -> win32ConsoleApplication에서 새 프로젝트를 만들고이 코드를 주 파일에 붙여 넣습니다. 그것의 작동하지 않습니다. 그러면 오류 메시지에 첫 번째 파일에 #include "stdafx.h"
을 추가해야한다고 나와 있습니다.
Error 1 error C2146: syntax error : missing ';' before identifier 'handler' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1
Error 2 error C2182: 'interrupt' : illegal use of type 'void' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1
Error 4 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 6 error C2086: 'int interrupt' : redefinition c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 7 error C2143: syntax error : missing ';' before '(' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 8 error C2059: syntax error : ')' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 9 error C2059: syntax error : ';' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 10 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 44 1 ConsoleApplication1
Error 11 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1
Error 12 error C3861: 'getvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1
Error 13 error C3861: 'setvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 48 1 ConsoleApplication1
Error 14 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 67 1 ConsoleApplication1
이러한 오류는이 라인에 관련된 :
void interrupt handler(__CPPARGS);
void interrupt (*oldhandler)(__CPPARGS);
그리고 사용 : 이렇게 한 후, 이것이 내 주요 오류 목록입니다 clrscr();
내 운영 체제 윈도우입니다 10-64bit Visual Studio에서 c/C++로 처음 프로그래밍되었습니다. 나는 Turbo C++과 devC++에서 몇 가지 작업을하기도합니다. 그러나 Turbo C++만이이 샘플을 실행하고 devC++도 실행하지 않습니다. diffrenses는 무엇이며 어떻게 해결해야합니까? 감사합니다.
MS-DOS가 죽었습니다. –
MS-DOS가 계속 남아 있습니다. 그리고 우린 그것을 죽였어. 모든 살인자의 살인자는 어떻게 우리 자신을 위로해야합니까? 세상이 아직 소유하고있는 모든 것 중 가장 거룩하고 가장 강했던 것이 우리의 칼 아래에서 죽음으로 피가났습니다. 누가이 피를 우리에게서 닦아 낼 것입니까? –
MS-DOS가 죽었습니다. 그것에 대해 의심의 여지가 없습니다. 그 장례식의 기록은 성직자, 서기관, 장의사 및 수석 부인이 서명했습니다. Windows가 서명했습니다. 그리고 Windows의 이름은 '변경'에 좋았습니다. – user4581301