[c언어]오류수정좀. 함수는짯는데;; 주석이 있어야하나.ㅜㅜ

lh8557의 이미지

#include <stdio.h>


// 문자를 저장하는 스택과 함수 정의 
#define MAX_EXPR_SIZE  100
#define CHAR_STACK_SIZE 100
#define INT_STACK_SIZE 100
char char_stack[CHAR_STACK_SIZE];

int char_top = -1;
int int_top = -1;

int char_Isfull()
{
	if(char_top>=CHAR_STACK_SIZE-1)
		return 1;
	else 
		return 0;
}

int char_Isempty()
{
	if(char_top<=-1)
		return 1;
	else 
		return 0;
}

void char_stack_full()
{
	printf("Stack is Full! : \n");
}

void char_stack_add(char item)
{
	if(char_top>=CHAR_STACK_SIZE-1)
	{
		char_stack_full();
		return;
	}
	char_stack[++char_top] = item;
}

char char_stack_empty()
{
	printf("Stack is Empty! : \n");
	char_stack[0] = '0';
	return char_stack[0];
}

char char_stack_delete()
{
	char item;
	if(char_top <= -1)
		return char_stack_empty();
		item = char_stack[char_top--];
	return item;
}


// 문자를 저장하는 스택 정의 끝 

int int_stack[INT_STACK_SIZE];

int int_Isfull()
{
	if(int_top>=INT_STACK_SIZE-1)
		return 1;
	else 
		return 0;
}

int int_Isempty()
{
	if(int_top<=-1)
		return 1;
	else 
		return 0;
}

void int_stack_full()
{
	printf("Stack is Full! : \n");
}

void int_stack_add(int item)
{
	if(int_top>=INT_STACK_SIZE-1)
	{
		int_stack_full();
		return;
	}
	int_stack[++int_top] = item;
}

int int_stack_empty()
{
	printf("Stack is Empty! : \n");
	int_stack[0] = '0';
	return int_stack[0];
}

int int_stack_delete()
{
	int item;
	if(int_top <= -1)
		return int_stack_empty();
		item = int_stack[int_top--];
	return item;
}
//인트스택 함수구현
// 함수 Prototype 

int operand(char x);
int Isp(char x);
int Icp(char x);
void postfix(char *token, char *post);
int eval(char *post);

void main(void)
{
	char expr[MAX_EXPR_SIZE];
	char post[50];
	char c = 'y';
	while(c=='y')
	{
		printf("enter infix expression : \n");
		scanf("%s", expr);
		postfix(expr, post);
		printf("postfix notation : \n%s", post);
		printf("value : \n%d", eval(post));
		printf("\nDo you want to do another expression('y'or'n')? ");
		scanf("%s", &c);
	}
}


int operand(char x)
{
	char op[8] = {'(', ')', '+', '-', '*', '/', '%', '\0'};
	for(int i=0; i<8; i++)
		if(op[i]==x)
			return 0;
	return 1;
}

int Isp(char x)
{
	char op[8] = {'(', ')', '+', '-', '*', '/', '%', '\0'};
	int sp[8] = {0,19,12,12,13,13,13,0};
	int i;
	for(i=0; i<8; i++)
		if(op[i]==x)
			return sp[i];
	printf(" Isp error \n");
	return 0;
}

int Icp(char x)
{
	char op[8] = {'(', ')', '+', '-', '*', '/', '%', '\0'};
	int cp[8] = {0,19,12,12,13,13,13,0};
	int i;
	for(i=0; i<8; i++)
		if(op[i]==x)
			return cp[i];
	printf(" Icp error \n");
	return 0;
}

void postfix(char *token, char *post)
{
	char x;
	int ipost = 0;
	char_top = 0;
	
	for(int i=0; token[i]!='\0'; i++)
	{
		x=token[i];
		if(operand(x))post[ipost++] = x;
		else if(x == ')' )
		{
			while(char_stack[char_top]!='(')
				post[ipost++] = char_stack_delete();
			char_stack_delete();
		}
		else
		{
			while(Isp(char_stack[char_top])>=Icp(x))
				post[ipost++] = char_stack_delete();
			char_stack_add(x);
		}
	}

	while((x=char_stack_delete()) != '\0')
		post[ipost++] = x;
		post[ipost] = '\0';
	return;
}  

int eval(*post)
{
	int n = 0;
	int int_top = 0;
	int_stack[0] = '\0';
	int ipost = 0;
	while(post[ipost] != '\0')
	{
		
		if(post[ipost] == operand)
		{
			stack_add(&top, post[ipost] - '0');
						
		}
		else
		{
			op2 = stack_delete(&top);
			op1 = stack_delete(&top);
			switch(ipost)
			{
			case '+'  : stack_add(&top, op1+op2);
				break;
			case '-' : stack_add(&top, op1-op2);
				break;
			case '*' : stack_add(&top, op1*op2);
				break;
			case '/': stack_add(*top, op1/op2);
				break;
			case '%'   : stack_add(&top, op1%op2);
			}
		}
		
	}
	return stack_delete(&top);
}

오류는..

Compiling...
Cpp2.cpp
C:\Documents and Settings\나\My Documents\레포트\데이터구조\Cpp2.cpp(201) : error C2065: 'post' : undeclared identifier
C:\Documents and Settings\나\My Documents\레포트\데이터구조\Cpp2.cpp(201) : error C2100: illegal indirection
C:\Documents and Settings\나\My Documents\레포트\데이터구조\Cpp2.cpp(202) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
Error executing cl.exe.

Cpp2.obj - 3 error(s), 0 warning(s)

이렇게 나오는데 오류좀 잡아주세요

bugiii의 이미지

eval 함수의 라인이 202번인가요? 라인수 세기가 힘드네요... -_-;

저 위쪽의 함수 선언과 202번인가의 함수 정의의 선언부가 뭔가 틀린 것 같은데요...

타이핑 미스가 아닐까 합니다만... 뭔가 하나 빠졌습니다... 잘 보시면...

p.s. 레포트라 답은 알아서 찾으셔야... -_-;

lh8557의 이미지

예..계속 수정해보고는 있는데..계속 오류가

늘어나네요..ㅜㅜ

bugiii의 이미지

좀 힘드시더라도 찬찬히 해보시면... 누구나 처음엔 다 그랬습니다...

lh8557의 이미지

네...감사합니다..ㅜㅜ

litdream의 이미지

너무 열심히 고치고 계셨군요... ^^;
Version control 을 하셨더라면 하는 아쉬움이 남습니다.
제가 찾은것은 eval() 의 문제입니다.

1. int eval(*post) 이렇게만 하면 당연히 컴파일이 안되죠.
아마 int eval(char *post) 를 하시고 싶으셨던거죠?

2. if (post[ipost] == operand) 이러면 당연히
operand 는 함수인데, 인자를 못받으니 에러가 나겠죠?
if (post[ipost] == operand(post[ipost]) ) 를
하시고 싶으셨던거겠죠?

그런데, 이 다음에 약간의 문제가 있군요.
stack_add(&top, ... ) 라인에서..

top 이란 변수 자체는 정의 안하셨는데,
global 변수로 int_top 과 char_top 을 정의해놓으셨는데,
로컬 변수로 int_top 이 또 보이는군요?
postfix() 에서도 char_top 을 따로 정의 하셨더군요?
자세히 읽지는 않았지만, 변수를 global 로 잡으려는 의도셨을텐데..
global 과 local 이름이 같을때, 지금은 구별하실수 있더라도,
장기적으로 이것은 별로 바람직하진 않을겁니다.

그럼..

삽질의 대마왕...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.