'='문자열에 추가 할어떻게 내 배열의 끝에서 <code>=</code>을 추가 한 다음이 내가 내 공간을 할당하는 방법입니다 0</p> <p>를 추가하여 종료하려고
char* postExpr = malloc(sizeof(char)*MAX_LEN);
많은 방법을 시도했지만 여전히 문자열 끝에 '='문자를 추가하지 못하고 있습니다. 다른 모든 문자는 잘 작동합니다. 내가 infExpr [I]에
postExpr[postLen++] = 61;
postExpr[postLen++] = '=';
postExpr[postLen++] = infExpr[i];
노력이 무엇
이 값을 '='저장
편집 : 코드에서
char* infix2postfix (const char* infExpr) {
char* postExpr = malloc (sizeof(char)*MAX_LEN);
if(postExpr == NULL)
return NULL;
tStack* s = (tStack*) malloc(sizeof(tStack));
if(s == NULL)
{
free(postExpr);
return NULL;
}
unsigned postLen = 0;
for(int i = 0; i< MAX_LEN; i++)
{
switch(infExpr[i])
{
case '*':
case '/':
case '+':
case '-': doOperation(s,infExpr[i],postExpr,&postLen); break;
case '(': stackPush(s,infExpr[i]); break;
case ')': untilLeftPar(s,postExpr,&postLen); break;
case '=':
while(!stackEmpty(s))
{
stackTop(s,&postExpr[postLen++]);
stackPop(s);
}
postExpr[postLen++] = '='; //NO APPEND HERE!!!
postExpr[postLen++] = 0;
postLen = MAX_LEN;
break;
case 0:
postExpr[postLen++] = '=';
postExpr[postLen++] = 0;
postLen = MAX_LEN;
break;
default: postExpr[postLen++] = infExpr[i]; break;
}
}
return postExpr;
}
전체 코드를 표시하십시오. 이 캐릭터에는 특별한 것이 없습니다. –
여기에 게시 된 내용만으로는 문제를 표시하기에 충분하지 않습니다. 질문을 [최소, 완전하고 검증 가능한 예] (http://stackoverflow.com/help/mcve)로 업데이트하십시오. – dbush
게시물 자체가 코드에서 잘리는 것을 보지 못했습니다. –