我不知道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)
展开
 我来答
vivia_c
2013-10-18 · 超过13用户采纳过TA的回答
知道答主
回答量:42
采纳率:0%
帮助的人:37.8万
展开全部
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"); 
}
    }
}
小白范
2013-10-18 · TA获得超过358个赞
知道小有建树答主
回答量:309
采纳率:50%
帮助的人:291万
展开全部
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 : '}'

语法错误,检查一下“{”和“}”是否配对。
追问
我检查了,匹配的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
vicejack1980
2013-10-18
知道答主
回答量:7
采纳率:0%
帮助的人:3.4万
展开全部
你想干什么?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哪里去了!?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
深海_蓝鱼
2013-10-18 · TA获得超过423个赞
知道小有建树答主
回答量:178
采纳率:0%
帮助的人:243万
展开全部
75行的 S=Init_Stack(); 改成 Init_Stack(&s);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式