2011-09-22 1 views
0

로 난 SIC/XE를 .ASM 파일 symtab을 만들 쓴 코드 ....파일 처리 문제 (하나 개 이상의 필드를 가지는 파일) 그것이 여기

#include<iostream> 
#include<fstream> 
#include<iomanip> 
#include"aviasm.h" 
using namespace std; 

void aviasm::crsymtab() 
{ 

ofstream outs("symtab.txt",ios::out);//creating the symtab 
ofstream outi("intermfile.txt",ios::out);//creating the intermediate file 
ifstream in("asmfile.txt",ios::in);//opening the asmfile which i have already written 
in.seekg(0,ios::beg); 


char c; 
string str[3]; 
string subset; 
long locctr=0; 
int i=0; 


while((c=in.get())!=EOF) 
{ 
    in.putback(c); 
    while((c=in.get())!='\n') 
    { 
     in.putback(c); //putting back the first encountered letter 
     in>>str[i++]; //the asm file has three or less fields in every row 
    } 

    if(str[0].size()!=0 && str[1].size()!=0 && str[2].size()!=0)//if all 3 are there 
    { 

     if(str[1]=="start") 
     { 
      outi<<hex<<locctr; 
      outs<<str[1]<<" "<<locctr<<"\n"; 
      outs<<resetiosflags(ios::hex); 
      outi<<" "<<str[0]<<" "<<str[1]<<" "<<str[2]<<"\n"; 
      locctr=stol(str[2],0,16); 
     }//str[1]=start 
    }//end of all the three fields 
} 
in.close(); 
outi.close(); 
outs.close(); 
}//end of crsymtab 

이다 연관된 .. ... 여기에 샘플 sic/xe .asm file ..... 위의 코드에서 위 코드를 제외한 코드의 전체 부분을 주석으로 처리하더라도 문제가 발생하기 때문에 전체 코드가 포함되어 있지 않습니다. 코드를 실행할 때마다 발생합니다 :

  1. 메시지 상자가있는 경우 : 'Unhandled exception at 0x00ba7046 in aviasm.exe: 0xC0000005: Access violation writing location 0xcccccccc.'이 표시됩니다. 콘솔에 또한

    static void __CLRCALL_OR_CDECL assign(_Elem& _Left, const _Elem& _Right) { // assign an element _Left = _Right; }

  2. , I 출력 몇 마디 : 내 프로그램은 또한 iosfwd(std::char_traits<char>)라는 이름의 파일이 선 다음 함수의 _Left=_Right;에서 화살표가 나타납니다 ...
    디버깅 모드로 들어갑니다 블록 시작과 끝 부분에서이 함수가 작동하는지 확인하려면 str[1]="start" ... 두 줄이 모두
    일 뿐이며 입력이 성공적으로 프로그램에 의해 수행 된 것임을 확신합니다. asm 파일 ed this), intermfile 및 symtab에 출력되는 행이 없습니다 ... plz help ??

+0

"코드를 실행할 때마다 문제가 발생합니다."및 "컴파일 할 때 예외가 발생했습니다."잘 맞지 않는 것 같습니다 ... – PlasmaHH

답변

1

디버거에서 프로그램을 실행해야합니다. Windows를 사용하는 경우 MSVC는 디버그 환경을 제공합니다. Linux를 사용하는 경우 -g으로 프로그램을 컴파일하고 gdb 디버거 인 gdb ./myprog을 실행하십시오. 즉시이 라인에 그것을 발견 할 것이다 :

in>>str[i++]; //the asm file has three or less fields in every row 

istr 배열의 크기를 초과 4의 값을 가지고 있습니다.

+0

@rob ... 저는 최대 값이 3입니다 (4) ...하지만 if (i <= 1) i ++을 작성하여 문제를 해결했지만 ... – avinash

+0

코드를 실행할 때 여전히 예외가 발생합니다 ... 코드가 입력되지 않는 이유 intermfile과 symtab이 성공적으로 asmfile에서 꺼내 진 경우 – avinash

+0

데이터가 asmfile에서 성공적으로 입력되지 않았습니다. asmfile에서 데이터를 추출하는 동안 프로그램이 중단됩니다. 따라서 다른 파일로 출력되는 행에는 절대 도달하지 않습니다. –

관련 문제