c语言调试问题!
发布网友
发布时间:2023-05-07 00:53
我来回答
共1个回答
热心网友
时间:2023-11-24 11:59
ungetch()是库函数中的函数,原型是这样的:int ungetch(int);
你自己又定义一个类型返回值类型不一样的,那就不要包含下面这个头文件了嘛:
#include <conio.h>
补充:
搂主,你说的调试不是单步调试吧?编译都有错,根本调试不了。
--------------------Configuration: aaa - Win32 Debug--------------------
Compiling...
b.cpp
E:\MYDOC\VC6\aaa\b.cpp(75) : error C2556: 'void __cdecl ungetch(int)' : overloaded function differs only by return type from 'int __cdecl ungetch(int)'
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
E:\MYDOC\VC6\aaa\b.cpp(75) : error C2371: 'ungetch' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
E:\MYDOC\VC6\aaa\b.cpp(81) : error C2137: empty character constant
E:\MYDOC\VC6\aaa\b.cpp(111) : error C2556: 'void __cdecl ungetch(int)' : overloaded function differs only by return type from 'int __cdecl ungetch(int)'
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
Error executing cl.exe.
b.obj - 4 error(s), 0 warning(s)
能编译通过的如下,修改了两处:
#include <stdio.h>
#include <stdlib.h>
//#include <conio.h> //自己定义了函数库中的函数,就不要使用函数库了
#define MAXOP 100
#define NUMBER '0'
int getop(char []);
void push(double);
double pop(void);
main()
{
int type;
double op2;
char s[MAXOP];
while ((type=getop(s))!=EOF) {
switch(type) {
case NUMBER:
push(atof(s));
case '+':
push(pop()+pop());
case '*':
push(pop()*pop());
case '-':
op2=pop();
push(pop()-op2);
break;
case '/':
op2=pop();
if(op2!=0.0)
push(pop()/op2);
else
printf("error:zero divisor\n");
break;
case '\n':
printf("\t%.8g\n",pop());
break;
default:
printf("error:unknown command %s\n",s);
break;
}
}
return 0;
}
#define MAXVAL 100
int sp=0;
double val[MAXVAL];
void push(double f)
{
if (sp<MAXVAL)
val[sp++]=f;
else
printf("error:stack fill,can't push %g\n",f);
}
double pop(void)
{
if (sp>0)
return val[--sp];
else {
printf("error: stack empty\n");
return 0.0;
}
}
#include <ctype.h>
int getch(void);
void ungetch(int);
int getop(char s[])
{
int i,c;
while ((s[0]=c=getch())==' '||c=='\t')//注意空格的写法
;
s[1]='\0';
if (!isdigit(c)&&c!='.')
return c;
i=0;
if (isdigit(c))
while (isdigit(s[++i]=c=getch()))
;
if (c=='.')
while (isdigit(s[++i]=c=getch()))
;
s[i]='\0';
if (c!=EOF)
ungetch(c);
return NUMBER;
}
#define BUFSIZE 100
char buf[BUFSIZE];
int bufp=0;
int getch(void)
{
return (bufp>0)?buf[--bufp] :getchar();
}
void ungetch(int c)
{
if(bufp >=BUFSIZE)
printf("ungetch: too many chatacters\n");
else
buf[bufp++]=c;
}
热心网友
时间:2023-11-24 11:59
ungetch()是库函数中的函数,原型是这样的:int ungetch(int);
你自己又定义一个类型返回值类型不一样的,那就不要包含下面这个头文件了嘛:
#include <conio.h>
补充:
搂主,你说的调试不是单步调试吧?编译都有错,根本调试不了。
--------------------Configuration: aaa - Win32 Debug--------------------
Compiling...
b.cpp
E:\MYDOC\VC6\aaa\b.cpp(75) : error C2556: 'void __cdecl ungetch(int)' : overloaded function differs only by return type from 'int __cdecl ungetch(int)'
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
E:\MYDOC\VC6\aaa\b.cpp(75) : error C2371: 'ungetch' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
E:\MYDOC\VC6\aaa\b.cpp(81) : error C2137: empty character constant
E:\MYDOC\VC6\aaa\b.cpp(111) : error C2556: 'void __cdecl ungetch(int)' : overloaded function differs only by return type from 'int __cdecl ungetch(int)'
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
Error executing cl.exe.
b.obj - 4 error(s), 0 warning(s)
能编译通过的如下,修改了两处:
#include <stdio.h>
#include <stdlib.h>
//#include <conio.h> //自己定义了函数库中的函数,就不要使用函数库了
#define MAXOP 100
#define NUMBER '0'
int getop(char []);
void push(double);
double pop(void);
main()
{
int type;
double op2;
char s[MAXOP];
while ((type=getop(s))!=EOF) {
switch(type) {
case NUMBER:
push(atof(s));
case '+':
push(pop()+pop());
case '*':
push(pop()*pop());
case '-':
op2=pop();
push(pop()-op2);
break;
case '/':
op2=pop();
if(op2!=0.0)
push(pop()/op2);
else
printf("error:zero divisor\n");
break;
case '\n':
printf("\t%.8g\n",pop());
break;
default:
printf("error:unknown command %s\n",s);
break;
}
}
return 0;
}
#define MAXVAL 100
int sp=0;
double val[MAXVAL];
void push(double f)
{
if (sp<MAXVAL)
val[sp++]=f;
else
printf("error:stack fill,can't push %g\n",f);
}
double pop(void)
{
if (sp>0)
return val[--sp];
else {
printf("error: stack empty\n");
return 0.0;
}
}
#include <ctype.h>
int getch(void);
void ungetch(int);
int getop(char s[])
{
int i,c;
while ((s[0]=c=getch())==' '||c=='\t')//注意空格的写法
;
s[1]='\0';
if (!isdigit(c)&&c!='.')
return c;
i=0;
if (isdigit(c))
while (isdigit(s[++i]=c=getch()))
;
if (c=='.')
while (isdigit(s[++i]=c=getch()))
;
s[i]='\0';
if (c!=EOF)
ungetch(c);
return NUMBER;
}
#define BUFSIZE 100
char buf[BUFSIZE];
int bufp=0;
int getch(void)
{
return (bufp>0)?buf[--bufp] :getchar();
}
void ungetch(int c)
{
if(bufp >=BUFSIZE)
printf("ungetch: too many chatacters\n");
else
buf[bufp++]=c;
}
热心网友
时间:2023-11-24 11:59
ungetch()是库函数中的函数,原型是这样的:int ungetch(int);
你自己又定义一个类型返回值类型不一样的,那就不要包含下面这个头文件了嘛:
#include <conio.h>
补充:
搂主,你说的调试不是单步调试吧?编译都有错,根本调试不了。
--------------------Configuration: aaa - Win32 Debug--------------------
Compiling...
b.cpp
E:\MYDOC\VC6\aaa\b.cpp(75) : error C2556: 'void __cdecl ungetch(int)' : overloaded function differs only by return type from 'int __cdecl ungetch(int)'
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
E:\MYDOC\VC6\aaa\b.cpp(75) : error C2371: 'ungetch' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
E:\MYDOC\VC6\aaa\b.cpp(81) : error C2137: empty character constant
E:\MYDOC\VC6\aaa\b.cpp(111) : error C2556: 'void __cdecl ungetch(int)' : overloaded function differs only by return type from 'int __cdecl ungetch(int)'
c:\program files\microsoft visual studio\vc98\include\conio.h(104) : see declaration of 'ungetch'
Error executing cl.exe.
b.obj - 4 error(s), 0 warning(s)
能编译通过的如下,修改了两处:
#include <stdio.h>
#include <stdlib.h>
//#include <conio.h> //自己定义了函数库中的函数,就不要使用函数库了
#define MAXOP 100
#define NUMBER '0'
int getop(char []);
void push(double);
double pop(void);
main()
{
int type;
double op2;
char s[MAXOP];
while ((type=getop(s))!=EOF) {
switch(type) {
case NUMBER:
push(atof(s));
case '+':
push(pop()+pop());
case '*':
push(pop()*pop());
case '-':
op2=pop();
push(pop()-op2);
break;
case '/':
op2=pop();
if(op2!=0.0)
push(pop()/op2);
else
printf("error:zero divisor\n");
break;
case '\n':
printf("\t%.8g\n",pop());
break;
default:
printf("error:unknown command %s\n",s);
break;
}
}
return 0;
}
#define MAXVAL 100
int sp=0;
double val[MAXVAL];
void push(double f)
{
if (sp<MAXVAL)
val[sp++]=f;
else
printf("error:stack fill,can't push %g\n",f);
}
double pop(void)
{
if (sp>0)
return val[--sp];
else {
printf("error: stack empty\n");
return 0.0;
}
}
#include <ctype.h>
int getch(void);
void ungetch(int);
int getop(char s[])
{
int i,c;
while ((s[0]=c=getch())==' '||c=='\t')//注意空格的写法
;
s[1]='\0';
if (!isdigit(c)&&c!='.')
return c;
i=0;
if (isdigit(c))
while (isdigit(s[++i]=c=getch()))
;
if (c=='.')
while (isdigit(s[++i]=c=getch()))
;
s[i]='\0';
if (c!=EOF)
ungetch(c);
return NUMBER;
}
#define BUFSIZE 100
char buf[BUFSIZE];
int bufp=0;
int getch(void)
{
return (bufp>0)?buf[--bufp] :getchar();
}
void ungetch(int c)
{
if(bufp >=BUFSIZE)
printf("ungetch: too many chatacters\n");
else
buf[bufp++]=c;
}