2016-11-27 108 views
-2

我是一名計算機專業的學生,​​最近學會了一對情侶在網絡搜索,我想出了這個代碼後使用C. 中斷中斷工作:C/C++ - 在Visual Studio 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++工作完美秒錶。 我改變了我的IDE現在使用Visual Studio 2013年,當我在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();

我操作的系統是windows 10-64bit並且它是我第一次在visual studio中用c/C++編程。我在Turbo C++和devC++中做過一些,但只有Turbo C++運行這個例子,甚至不是devC++。什麼是diffrenses,我應該如何解決這個問題? 感謝

+1

MS-DOS已死。 –

+2

MS-DOS仍然死機。我們殺了它。我們應該如何安慰自己,所有殺人犯的兇手?世界上所擁有的最神聖和最強大的東西已經在我們的刀下流血而死:誰會把這些血從我們身上抹去? –

+0

MS-DOS已死:首先。毫無疑問,無論如何。其埋葬登記簿由牧師,文員,承辦人和主要哀悼者簽署。 Windows簽署了它。而且Windows的名字對於改變,對於它選擇的任何東西都很有幫助。 – user4581301

回答

0

您在64位長的模式下工作,所以你不必訪問實模式BIOS中斷或MS-DOS服務。你的代碼有許多其他問題,但底線是沒有16位編譯器和仿真器(如64位Windows上沒有的NTVDM)就無法工作

+0

所以你的意思是我不能在Visual Studio解決這個問題或者我應該安裝一些其他插件或編譯器呢?我現在應該怎麼做?有沒有任何現代的IDE可以作爲渦輪C + +沒有任何問題? –

+0

@ mohammadfallah.rasoulnejad您需要安裝像DOSBox或emu8086這樣的8086模擬器,並將代碼寫入其中的編譯器 - 在64位操作系統中無法模擬16位實模式。請參閱http://wiki.osdev.org/Real_Mode –