전위를 후위로 바꾸는 예제 c언어
마호
질문 제목 : operator
질문 내용 :
#include stdio.h
#include string.h
#define OPERATORS +-*/
void preToPostFix (char* preFixIn, char* exprOut);
int findExprLen (char* exprIn);
int main(void)
{
char preFixExpr[256]=-+*ABC/EF;
char postFixExpr[256]=;
printf(Begin prefix to postfix conversion \n\n);
preToPostFix (preFixExpr, postFixExpr);
printf(prefix expr:%-s\n, preFixExpr);
printf(postfix expr:%-s\n, postFixExpr);
printf(\n End prefix to postfix conversion \n);
return 0;
}
void preToPostFix (char* preFixIn, char* postFix)
{
char operator [2];
char postFix1[256];
char postFix2[256];
char temp[256];
int lenPreFix;
if(strlen(preFixIn)==1)
{
*postFix=*preFixIn;
*(postFix+1) = \O;
return;
}
*operator=*preFixIn;
*(operator+1)=\O;
lenPreFix=findExprLen (preFixIn+1);
strncpy(temp, preFixIn+1, lenPreFix);
*(temp+lenPreFix)=\O;
preToPostFix(temp, postFix1);
strcpy (temp, preFixIn+1+lenPreFix);
preToPostFix(temp, postFix2);
strcpy (postFix, postFix1);
strcpy (postFix, postFix2);
strcpy (postFix, operator);
return;
}
int findExprLen (char* exprIn)
{
int len1;
int len2;
if(strcspn(exprIn,OPERATORS)==0)
{
len1=findExprLen(exprIn+1);
len2=findExprLen(exprIn+1+len1);
}
else
len1=len2=0;
return len1+len2+1;
}
책에 있는 거 고대로 쳤는데 빨간색 부분이 잘못됐다고 나오는데 어떻게 하면 되나요?
추가 질문으로 확장자명을 .c로 했는데
char operator[2]; 이부분이 에러가 납니다. 검색해보니 c++에서 쓰는 거라고 나오는데
처음 프로젝트 생성할때 따로 설정해줘야되는 부분이 있는지 알켜주세요
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2658305 | strcpy와 포인터 그리고 메모리 할당에 대한 질문 입니다./ (3) | 나라우람 | 2024-06-14 |
2658274 | 포인터 문자열 역으로 출력?ㅠ | 어서와 | 2024-06-14 |
2658192 | C언어기초3문제 (3) | 해샘찬 | 2024-06-13 |
2658165 | 로또게임질문 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ | 내꽃 | 2024-06-13 |
2658136 | 구조체 부분에서 막혔습니다.. (3) | 난슬 | 2024-06-13 |
2658106 | c언어 간단한 질문입니다 (4) | 아잉누님 | 2024-06-13 |
2658077 | security가 붙은 함수 관련 질문 | 횃대비 | 2024-06-12 |
2658050 | 기초 c언어 프로그램 짜는데 어려워서 글올려요 | 꺆잉 | 2024-06-12 |
2658021 | #define 문 정말 간단한 질문있습니다. | 심플포텐 | 2024-06-12 |
2657962 | IPv6에서 RAS 사용요 | 상1큼한렩 | 2024-06-11 |
2657935 | 도와주세요 배열및 함수관련. (4) | 하루키 | 2024-06-11 |
2657885 | 두개의 소문자입력뒤 비트연산자로 대문자오바꾸기 | 풀잎 | 2024-06-11 |
2657830 | 경우의 수 구하기.. (1) | 흰우유 | 2024-06-10 |
2657806 | 연산자 질문요 (1) | 네코 | 2024-06-10 |
2657782 | 콘솔창 꽉채우기 | 미쁘다 | 2024-06-10 |
2657754 | 유니코드 기반으로 문자 입출력받는데 안됩니다 | 어리버리 | 2024-06-09 |
2657728 | 포인터 배열도 동적할당(malloc)를 통해서 생성이 가능한가요? | 우미 | 2024-06-09 |
2657700 | 오류 해석을 못하겠어요. | 해길 | 2024-06-09 |
2657642 | 출력부분에서.. | 앨버트 | 2024-06-08 |
2657620 | 파일 입출력 함수 반복문 .. | 서리서리 | 2024-06-08 |