作者hunkchen2016 (我的鸡巴女友)
看板C_and_CPP
标题[问题] 请问字串堆叠的问题???
时间Thu Jun 7 15:51:46 2018
请问各位强者
我想把字串写入堆叠,然後再从堆叠中取出
请问我的程式该怎麽改!!因为一直出现错误
#include <stdio.h>
#include <stdlib.h>
#define MAXSTACK 100 /*定义最大堆叠容量*/
char stack[MAXSTACK]; //堆叠的阵列宣告
int top=-1; //堆叠的顶端
int isEmpty();
void push(char string);
char pop();
int main(int argc, char *argv[]) {
char string[3];
int i;
printf("请依序输资料:\n");
fgets(string[0], 100, stdin);
push(string)
fgets(string[0], 100, stdin);
push(string);
fgets(string[0], 100, stdin);
push(string);
printf("====================\n");
while(!isEmpty()){
printf("堆叠弹出的顺序为:%d\n",pop());
}
pop();
return 0;
}
/*判断是否为空堆叠*/
int isEmpty()
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
/*将指定的资料存入堆叠*/
void push(string)
{
if(top>=MAXSTACK){
printf("堆叠已满,无法再加入\n");
}
else
{
top++;
stack[top]=string;
}
}
/*从堆叠取出资料*/
char pop(){
char data;
if(isEmpty())
{
printf("堆叠已空\n");
}else
{
data=stack[top];
top--;
return data;
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 61.228.242.36
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1528357909.A.6AF.html
1F:→ Schottky: 字串处理的部分整个错了 06/07 15:54
2F:推 jerryh001: fgets用法完全错误 06/07 15:54
3F:→ jerryh001: 而且这种语法错误应该会有错误讯息 下次请先google 06/07 15:56
4F:→ sarafciel: 你如果想印字元回圈内那个printf要用%c才对 06/07 20:08
5F:推 cphe: 应该不只上面提到的问题....... 06/16 12:06