-7
이것은 내 대학에서 가지고있는 숙제입니다. 텍스트 파일의 줄에서 폴란드어 표기법을 읽어야합니다. 텍스트 파일의 표현식은 "/ 2 3"이고이를 역 폴란드어 표기법으로 바꾸어야합니다. 이 오류가 계속 발생합니다 : 0xC0000005 : 0x00000000 위치를 읽는 액세스 위반.0xC0000005 : 액세스 위반 읽기 위치가 0x00000000입니다. C++
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;
}
나는 오류 내 코드의이 부분에있을 수 있습니다 생각 : 누군가가 나를 도울 수 있다면 내가 5 시간에 숙제를 제출해야하기 때문에
가void PrefixToPostfix()
{
for (int *i = 0; *i <= top2; i++)
{
c = prefix[*i];
, 나는 매우 감사 할 것입니다. :)
http://ericlippert.com/2014/03/05/how-to-debug-small-programs/의 – Biffen
가능한 중복 [ 0xC0000005 : 0x00000000 위치를 읽는 액세스 위반] (http://stackoverflow.com/questions/10478941/0xc0000005-access-violation-reading-location-0x00000000) – Marvin
시행 착오를 통해 C++를 배우려고하지 마십시오. 아무 것도 얻을 수 없습니다. . 좋은 책 대신 체계적으로 배웁니다. –