중위 어에서 접두어로 변환 할 코드를 작성하려고합니다. 여기있다 :이상한 기호가 C 출력에 표시됩니다. 모든 단서?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top = -1, size;
int precedence(char c)
{
if (c=='+' || c=='-')
return 1;
if (c=='*' || c=='/')
return 2;
if (c=='^')
return 3;
}
/* push the given data into the stack */
void push(char *stack, char data) {
top++;
//printf("Top:%d, Size:%d\n",top,size);
if (top >= size) {
printf("Stack Overflow\n");
return;
}
//printf("Hello in PUSH\n");
stack[top] = data;
return;
}
/* pop the top element from the stack */
void pop(char *stack) {
if (top <= -1) {
printf("Stack Underflow!\n");
return;
}
stack[top] = '*';
top--;
return;
}
char peek(char *stack)
{
return stack[top];
}
void stackp(char *stack)
{
int r;
printf("Print Stack:\n");
for(r=0;r<top;r++)
printf("%c\n",stack[r]);
}
int main()
{
char data;
char ip[100];
int i,j;
printf("Enter the Input, Input can be of max 100 characters:\n");
scanf("%s", ip);
size=strlen(ip);
char op[size];
char stack[size];
for(i=size-1;i>-1;i--)
{
stackp(stack);// Print Stack
//printf("Hello\n");
//printf("%c ",ip[i]);// Print current element
if((ip[i]-'0')>0 && (ip[i]-'0')<9)
{
// printf("Hello\n");
strcat(op,&ip[i]);
printf("%s \n",op);
break;
}
else if(top==-1)
{
push(stack,ip[i]);
break;
}
else if(top!=-1 && ip[i]==')')// Brackets Condition
{
while(stack[top]!='(')
{
strcat(op,&ip[i]);
pop(stack);
}
}
else if(top!=-1 && (precedence(stack[top])-precedence(ip[i])>0))
{
while(precedence(stack[top])-precedence(ip[i])>0 || top!=-1)
{
strcat(op,&ip[i]);
pop(stack);
}
push(stack,ip[i]);
}
else
{
push(stack,ip[i]);
}
}
//printf("%s ",op);
}
나는 컴파일하고 실행한다. 나는 내 출력에 매우 strange looking symbol을 얻는다.
누군가 도대체 저에게 뭐라고 말할 수 있습니까? 어떻게 수정합니까?
그와 같은 비 인쇄 문자, 파이어 폭스가 비 인쇄 가능한 문자 U + 0001 표시하기 위해 사용하는 것이 무엇처럼 40 – tesseract
외모에 아스키 0 ~ 아마 뭔가를 최종
return
문을 추가합니다. 값 '1'을 가진 바이트를 출력하지 않음으로써이를 정정하십시오. 어떤 출력 진술이 출력되고 있는지 알아 낸 다음, 출력되는 var에 포함될 것으로 예상되는 내용이 왜 포함되어 있지 않은지 알아보십시오 – ikegamitesseract는 40 진수를 의미합니다. 20 진수는 20 진수이며, 문자 그대로 40 사이의 "중간"을 의미합니다 공간입니다. – ikegami