
我不知道c语言程序哪里出错了
typedefintElemType;#include"stdio.h"#include<stdlib.h>#include<string.h>#include<mall...
typedef int ElemType ;
#include "stdio.h"
#include<stdlib.h>
#include <string.h>
#include <malloc.h>
#define MAXSIZE 100 /* 栈初始向量大小 */
#define STACKINCREMENT 10 /* 存储空间分配增量 */
typedef struct
{
ElemType elem[MAXSIZE] ;
int top ;
}SqStack ;
void InitStack(SqStack *s)
{
s->top=-1;
}
int StackEmpty(SqStack s)
{
if(s.top==-1)
return 1;
else
return 0;
}
void push(SqStack *s , ElemType e)
{
if(s->top==MAXSIZE-1)
{
printf("Stack is full\n");
return;
}
s->top++;
s->elem[s->top]=e;
}
void pop(SqStack *s , ElemType *e)
{
if(s->top ==-1)
{
printf("Stack is empty\n");
return;
}
*e=s->elem[s->top];
s->top--;
}
void conversion(int n , int d)
{ /*将十进制整数N转换为d(2或8)进制数*/
SqStack S; int k, *e ;
S=Init_Stack();
while (n>0)
{
k=n%d ;
push(S,k) ;
n=n/d ;
}
/* 求出所有的余数,进栈 */
while (S.top!=0) /* 栈不空时出栈,输出 */
{
pop(S, e) ;
printf("%1d" , *e) ;
}
}
void main()
{
float n; int s;
scanf("%f",&n);
printf("请输入一个十进制数:");
printf("10-2转换请输入1\n");
printf("10-8转换请输入2\n");
printf("10-16转换请输入3\n");
printf("退出请输入 4\n");
printf("\n请选择: ");
scanf("%d",&s);
do
{
switch(s)
{
case 1:
conversion(n,2); break;
case 2:
conversion(n,8); break;
case 3:
conversion(n,16); break;
case 4:
break;
default:break;
}
}
}
-------------------Configuration: 2 - Win32 Debug--------------------
Compiling...
2.c
C:\Documents and Settings\NIT\桌面\2.c(75) : warning C4013: 'Init_Stack' undefined; assuming extern returning int
C:\Documents and Settings\NIT\桌面\2.c(75) : error C2115: '=' : incompatible types
C:\Documents and Settings\NIT\桌面\2.c(79) : error C2115: 'function' : incompatible types
C:\Documents and Settings\NIT\桌面\2.c(79) : warning C4024: 'push' : different types for formal and actual parameter 1
C:\Documents and Settings\NIT\桌面\2.c(85) : error C2115: 'function' : incompatible types
C:\Documents and Settings\NIT\桌面\2.c(85) : warning C4024: 'pop' : different types for formal and actual parameter 1
C:\Documents and Settings\NIT\桌面\2.c(106) : warning C4244: 'function' : conversion from 'float ' to 'int ', possible loss of data
C:\Documents and Settings\NIT\桌面\2.c(108) : warning C4244: 'function' : conversion from 'float ' to 'int ', possible loss of data
C:\Documents and Settings\NIT\桌面\2.c(110) : warning C4244: 'function' : conversion from 'float ' to 'int ', possible loss of data
C:\Documents and Settings\NIT\桌面\2.c(116) : error C2059: syntax error : '}'
执行 cl.exe 时出错.
2.exe - 1 error(s), 0 warning(s) 展开
#include "stdio.h"
#include<stdlib.h>
#include <string.h>
#include <malloc.h>
#define MAXSIZE 100 /* 栈初始向量大小 */
#define STACKINCREMENT 10 /* 存储空间分配增量 */
typedef struct
{
ElemType elem[MAXSIZE] ;
int top ;
}SqStack ;
void InitStack(SqStack *s)
{
s->top=-1;
}
int StackEmpty(SqStack s)
{
if(s.top==-1)
return 1;
else
return 0;
}
void push(SqStack *s , ElemType e)
{
if(s->top==MAXSIZE-1)
{
printf("Stack is full\n");
return;
}
s->top++;
s->elem[s->top]=e;
}
void pop(SqStack *s , ElemType *e)
{
if(s->top ==-1)
{
printf("Stack is empty\n");
return;
}
*e=s->elem[s->top];
s->top--;
}
void conversion(int n , int d)
{ /*将十进制整数N转换为d(2或8)进制数*/
SqStack S; int k, *e ;
S=Init_Stack();
while (n>0)
{
k=n%d ;
push(S,k) ;
n=n/d ;
}
/* 求出所有的余数,进栈 */
while (S.top!=0) /* 栈不空时出栈,输出 */
{
pop(S, e) ;
printf("%1d" , *e) ;
}
}
void main()
{
float n; int s;
scanf("%f",&n);
printf("请输入一个十进制数:");
printf("10-2转换请输入1\n");
printf("10-8转换请输入2\n");
printf("10-16转换请输入3\n");
printf("退出请输入 4\n");
printf("\n请选择: ");
scanf("%d",&s);
do
{
switch(s)
{
case 1:
conversion(n,2); break;
case 2:
conversion(n,8); break;
case 3:
conversion(n,16); break;
case 4:
break;
default:break;
}
}
}
-------------------Configuration: 2 - Win32 Debug--------------------
Compiling...
2.c
C:\Documents and Settings\NIT\桌面\2.c(75) : warning C4013: 'Init_Stack' undefined; assuming extern returning int
C:\Documents and Settings\NIT\桌面\2.c(75) : error C2115: '=' : incompatible types
C:\Documents and Settings\NIT\桌面\2.c(79) : error C2115: 'function' : incompatible types
C:\Documents and Settings\NIT\桌面\2.c(79) : warning C4024: 'push' : different types for formal and actual parameter 1
C:\Documents and Settings\NIT\桌面\2.c(85) : error C2115: 'function' : incompatible types
C:\Documents and Settings\NIT\桌面\2.c(85) : warning C4024: 'pop' : different types for formal and actual parameter 1
C:\Documents and Settings\NIT\桌面\2.c(106) : warning C4244: 'function' : conversion from 'float ' to 'int ', possible loss of data
C:\Documents and Settings\NIT\桌面\2.c(108) : warning C4244: 'function' : conversion from 'float ' to 'int ', possible loss of data
C:\Documents and Settings\NIT\桌面\2.c(110) : warning C4244: 'function' : conversion from 'float ' to 'int ', possible loss of data
C:\Documents and Settings\NIT\桌面\2.c(116) : error C2059: syntax error : '}'
执行 cl.exe 时出错.
2.exe - 1 error(s), 0 warning(s) 展开
4个回答
展开全部
typedef int ElemType ;
#include "stdio.h"
#include<stdlib.h>
#include <string.h>
#include <malloc.h>
#define MAXSIZE 100 /* 栈初始向量大小 */
#define STACKINCREMENT 10 /* 存储空间分配增量 */
typedef struct
{
ElemType elem[MAXSIZE] ;
int top ;
}SqStack ;
void InitStack(SqStack *s)
{
s->top=-1;
}
int StackEmpty(SqStack s)
{
if(s.top==-1)
return 1;
else
return 0;
}
void push(SqStack *s , ElemType e)
{
if(s->top==MAXSIZE-1)
{
printf("Stack is full\n");
return;
}
s->top++;
s->elem[s->top]=e;
}
void pop(SqStack *s , ElemType *e)
{
if(s->top ==-1)
{
printf("Stack is empty\n");
return;
}
*e=s->elem[s->top];
s->top--;
}
void conversion(int n , int d)
{ /*将十进制整数N转换为d(2或8)进制数*/
SqStack S; int k, *e ;
InitStack(&S);
while (n>0)
{
k=n%d ;
push(&S,k) ;
n=n/d ;
}
/* 求出所有的余数,进栈 */
while (S.top!=0) /* 栈不空时出栈,输出 */
{
pop(&S, e) ;
printf("%1d" , *e) ;
}
}
int main(void)
{
int n; int s;
printf("请输入一个十进制数:");
scanf("%f",&n);
printf("10-2转换请输入1\n");
printf("10-8转换请输入2\n");
printf("10-16转换请输入3\n");
printf("退出请输入 4\n");
printf("\n请选择: ");
while(EOF!=scanf("%d",&s))
{
if(s==4) break;
switch(s)
{
case 1:
conversion(n,2); break;
case 2:
conversion(n,8); break;
case 3:
conversion(n,16); break;
case 4:
break;
default:break;
printf("\n");
}
}
}
展开全部
2.c(75) : error C2115: '=' : incompatible types
原因:
void InitStack(SqStack *s)函数无返回值,但是调用时:S=Init_Stack();没有传参数却使用了返回值!
更改:
Init_Stack(&S);
2.c(79) : error C2115: 'function' : incompatible types
原因:
void push(SqStack *s , ElemType e)中第一个参数为SqStack的指针,但调用时却不是指针:
push(S,k) ;
更改:
push(&S,k);
2.c(116) : error C2059: syntax error : '}'
语法错误,检查一下“{”和“}”是否配对。
原因:
void InitStack(SqStack *s)函数无返回值,但是调用时:S=Init_Stack();没有传参数却使用了返回值!
更改:
Init_Stack(&S);
2.c(79) : error C2115: 'function' : incompatible types
原因:
void push(SqStack *s , ElemType e)中第一个参数为SqStack的指针,但调用时却不是指针:
push(S,k) ;
更改:
push(&S,k);
2.c(116) : error C2059: syntax error : '}'
语法错误,检查一下“{”和“}”是否配对。
追问
我检查了,匹配的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你想干什么?10进制数据转换为2进制,8进制,16进制数?
#include "stdio.h"
void main() {
int n; int s;
printf("输入数字和进制: 1 for 二进制, 2 for 8进制, 3or其他 for 16进制\n");
printf("数字: "); scanf("%u",&n);
printf("进制: "); scanf("%u",&s);
switch(s) {
case 1: {char s[64]; itoa(n, s, 2); printf("binary %s\n",s); break; }
case 2: {char s[16]; itoa(n, s, 8); printf("otect %s\n",s); break; }
default: printf("0x%X\n",n);break;
};
};
另外,你的do {} while语句的while哪里去了!?
#include "stdio.h"
void main() {
int n; int s;
printf("输入数字和进制: 1 for 二进制, 2 for 8进制, 3or其他 for 16进制\n");
printf("数字: "); scanf("%u",&n);
printf("进制: "); scanf("%u",&s);
switch(s) {
case 1: {char s[64]; itoa(n, s, 2); printf("binary %s\n",s); break; }
case 2: {char s[16]; itoa(n, s, 8); printf("otect %s\n",s); break; }
default: printf("0x%X\n",n);break;
};
};
另外,你的do {} while语句的while哪里去了!?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
75行的 S=Init_Stack(); 改成 Init_Stack(&s);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询