2016-11-11 12 views
-7

これは私の大学の宿題です。私は、テキストファイルの行からポーランド記法を読まなければなりません。テキストファイルの式は "/ 2 3"で、これを逆ポーランド表記にする必要があります。このエラーが発生し続ける:0xC0000005:0x00000000の場所を読み取るアクセス違反。0xC0000005:アクセス違反の読み取り場所0x00000000 C++

void PrefixToPostfix() 
{ 

for (int *i = 0; *i <= top2; i++) 
    { 
     c = prefix[*i]; 

誰かが私を助けることができる場合、私は5時間で宿題に有効にする必要がありますので、私は非常に感謝し、次のようになります。

int top = -1; 
char prefix[50]; 
void Push(char value) 
{ 
    top++; 
prefix[top] = value; 
} 
void Pop() 
{ 
if (top < 0) 
    cout << "The stack is empty." << endl; 
else 
{ 
    top--; 
} 
} 

char Top() 
{ 
return prefix[top]; 
} 

void Display() 
{ 
for (int i = 0; i <= top; i++) 
    cout << prefix[i] << " "; 
} 

bool isOperator(char c) 
{ 
if (c == '+' || c == '-' || c == '*' || c == '/') 
    return true; 
else 
    return false; 
} 

char c; 
char postfix[50]; 
int top2 = -1; 
void Push2() 
{ 
top2++; 
postfix[top2] = Top() + Top() + c; 
} 

void Display2() 
{ 
{ 
    for (int i = 0; i <= top2; i++) 
    cout << postfix[i] << " "; 
} 
}; 
void PrefixToPostfix() 
{ 

for (int *i = 0; *i <= top2; i++) 
{ 
    c = prefix[*i]; 
    if (isOperator) 
    { 
     Push2(); 
    } 
    else 
    { 
     top2++; 
     postfix[top2] = c; 
    } 

} 
} 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
char value; 
char c; 

ifstream file("Prefix.txt"); 
while (file >> value) 
{ 
    Push(value); 
} 
file.close(); 
PrefixToPostfix(); 
Display(); 
Display2(); 
cout << endl; 
system("PAUSE"); 
return 0; 
} 

私はエラーが私のコードのこの部分にあるかもしれないと思います。 :)

+0

http://ericlippert.com/2014/03/05/how-to-debug-small-programs/の – Biffen

+1

可能な重複は[ 0xC0000005:アクセス違反の読み取り場所0x00000000](http://stackoverflow.com/questions/10478941/0xc0000005-access-violation-reading-location-0x00000000) – Marvin

+1

試行錯誤でC++を習得しようとしないでください。 。代わりに良い本から系統的に学ぶ。 –

答えて

2

は、ここではポインタのための必要はありません。

for (int i = 0; i <= top2; i++) { 
    c = prefix[i]; } 
関連する問題