
我一个程序里面的错误找不出来大家帮忙看看;
#include<stdio.h>#include<stdlib.h>typedefstruct{inta[64];intx[64];inty[64];intcount[...
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int a[64];
int x[64];
int y[64];
int count[64];
int top;
} stack;
stack* init (int m, int n)
{
stack *q=malloc(sizeof(stack)); //提示错误在这里
if (q==NULL)
{ printf("init error\n"); return NULL;}
int j;
q->x[0]=m;
q->y[0]=n;
q->top=0;
for(j=0;j<64;j++)
q->count[j]=0;
return (q);
}
//
error C2440: 'initializing' : cannot convert from 'void *' to 'stack *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast 展开
#include <stdlib.h>
typedef struct
{
int a[64];
int x[64];
int y[64];
int count[64];
int top;
} stack;
stack* init (int m, int n)
{
stack *q=malloc(sizeof(stack)); //提示错误在这里
if (q==NULL)
{ printf("init error\n"); return NULL;}
int j;
q->x[0]=m;
q->y[0]=n;
q->top=0;
for(j=0;j<64;j++)
q->count[j]=0;
return (q);
}
//
error C2440: 'initializing' : cannot convert from 'void *' to 'stack *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast 展开
展开全部
stack *q=(stack *)malloc(sizeof(stack));
不能将'void *'转化为'stack *'
不能将'void *'转化为'stack *'
追问
如何修改!!
追答
stack* init(int m, int n)
{ int j;
stack *q=(stack *)malloc(sizeof(stack));
if (q==NULL)
{ printf("init error\n"); return NULL;}
q->x[0]=m;
q->y[0]=n;
q->top=0;
for(j=0;jcount[j]=0;
return (q);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询