S.base=(int *)realloc(S.base,(S.stacksize+kuozhan) * sizeof(int));
在程式開始寫了#include <malloc.h>怎么還是提示有錯啊 到底錯在哪了啊!!!!快哭啊都
uj5u.com熱心網友回復:
報的是什么錯?uj5u.com熱心網友回復:
沒realloc.h頭檔案但是有<malloc.h>頭檔案的時候是這樣的Compiling...
sdf.cpp
C:\Users\Administrator\Desktop\sdf.cpp(21) : error C2143: syntax error : missing ')' before ';'
C:\Users\Administrator\Desktop\sdf.cpp(21) : error C2143: syntax error : missing ')' before ';'
C:\Users\Administrator\Desktop\sdf.cpp(21) : error C2059: syntax error : ')'
C:\Users\Administrator\Desktop\sdf.cpp(21) : error C2059: syntax error : ')'
C:\Users\Administrator\Desktop\sdf.cpp(21) : error C2100: illegal indirection
執行 cl.exe 時出錯.
兩個都有的時候是這樣的
sdf.cpp
C:\Users\Administrator\Desktop\sdf.cpp(3) : fatal error C1083: Cannot open include file: 'reamlloc.h': No such file or directory
執行 cl.exe 時出錯.
uj5u.com熱心網友回復:
realloc 函式在頭檔案里:<stdlib.h>uj5u.com熱心網友回復:
寫上stdlib.h還是有錯 跟寫上realloc.h的報錯是一樣的uj5u.com熱心網友回復:
全部的代碼是這樣的#include <stdio.h>
#include <malloc.h>
#include <reamlloc.h>
#define kuozhan 10;
typedef struct{
int *base;
int *top;
int stacksize;
}zhan;
void init(zhan &S)
{
S.base=(int *)malloc(sizeof(int));
S.top=S.base;
}
void push(zhan &S,int e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(int *)realloc(S.base,(S.stacksize+kuozhan) * sizeof(int));
}
*****\\星號代表一些操作\\
*S.top++=e;
}
void pop(zhan &S,int e)
{
while(S.top){
if(S.top==S.base)break;
e=*--S.top;
printf("%d ",e);
}
}
void main()
{
int i;
zhan S;
init(S);
push(S,5);
pop(S,i);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113032.html
標籤:基礎類
