| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1723 人关注过本帖
标题:EOF怎么用啊,看看我下面的程序哪的问题
只看楼主 加入收藏
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
 问题点数:0 回复次数:5 
EOF怎么用啊,看看我下面的程序哪的问题

我输入EOF的时候为什么不结束啊

#include"stdio.h"
#include"stdlib.h"
#include"string.h"

#define INIT_SIZE 100
#define INCREMENT 10
#define error 0
#define null 0

typedef struct
{
char *top;
char *base;
int stacksize;
}SqStack;

void InitStack(SqStack &S);
void PushStack(SqStack &S, char e);
int PopStack(SqStack &S, char &e);
void ClearStack(SqStack &S);

void InitStack(SqStack &S)
{
S.base=(char*)malloc(sizeof(char)*INIT_SIZE);
if(!S.base) exit(1);
S.top=S.base;
S.stacksize=INIT_SIZE;

}

void PushStack(SqStack &S, char e)
{
if(S.top-S.stacksize==0)
{
S.base=(char*)realloc(S.base, sizeof(char)*(INIT_SIZE+INCREMENT));
S.top=S.base+INCREMENT;
S.stacksize+=INCREMENT;
}

*S.top++=e;
}

int PopStack(SqStack &S, char &e)
{
if(S.base==S.top) return error;
e=*(--S.top);
return 1;
}

void ClearStack(SqStack &S)
{
while(S.top!=S.base)
(--S.top);

}

void print(SqStack S)
{
char *p=S.base;
while(p!=S.top)
printf("%c",*p++);
}

int main()
{
char ch,e;
SqStack S;

InitStack(S);
ch=getchar();
while(ch!=EOF)
{
while(ch!='\n' && ch!=EOF)
{
switch(ch)
{
case'#':PopStack(S,*(S.top-1));break;
case'@':ClearStack(S);break;
default:PushStack(S,ch);break;
}
ch=getchar();
}
print(S);
ClearStack(S);
if(ch!=EOF)getchar();
}


return 0;
}

搜索更多相关主题的帖子: EOF SqStack void char 
2006-05-24 17:02
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
while(EOF!=(scanf("%c",&ch))&&ch!='\0')
你的switch(ch)错误,switch()只可以为整型,怎么可以为字符?

倚天照海花无数,流水高山心自知。
2006-05-24 17:17
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 

字符不也可当整数吗


明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-05-24 17:28
工藤♀新一
Rank: 1
等 级:新手上路
帖 子:140
专家分:0
注 册:2006-5-4
收藏
得分:0 
字符可以当整数?
如果字符要当整数的话,是需要转换的
例如:
char a='10';int b;
b=(int)a;

很高兴能和大家一起学习程序! QQ:114109098
2006-05-24 17:55
菜鸟上路
Rank: 4
等 级:贵宾
威 望:14
帖 子:1120
专家分:0
注 册:2006-3-21
收藏
得分:0 
以下是引用nuciewth在2006-5-24 17:17:00的发言:
while(EOF!=(scanf("%c",&ch))&&ch!='\0')
你的switch(ch)错误,switch()只可以为整型,怎么可以为字符?

是你老师说switch()只可以为整型吗?晕


2006-05-24 21:10
SunShining
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:31
帖 子:2215
专家分:0
注 册:2006-2-17
收藏
得分:0 

#include"stdio.h"
#include"stdlib.h"
#include"string.h"

#define INIT_SIZE 100
#define INCREMENT 10
#define error 0
#define null 0


typedef struct
{
char *top;
char *base;
int stacksize;
}SqStack;

void InitStack(SqStack &S);
void PushStack(SqStack &S, char e);
int PopStack(SqStack &S, char &e);
void ClearStack(SqStack &S);

void InitStack(SqStack &S)
{
S.base=(char*)malloc(sizeof(char)*INIT_SIZE);
if(!S.base) exit(1);
S.top=S.base;
S.stacksize=INIT_SIZE;

}

void PushStack(SqStack &S, char e)
{
if(S.top-S.stacksize==S.base)
{
S.base=(char*)realloc(S.base, sizeof(char)*(INIT_SIZE+INCREMENT));
S.top=S.base+INCREMENT;
S.stacksize+=INCREMENT;
}

*S.top++=e;
}

int PopStack(SqStack &S, char &e)
{
if(S.base==S.top) return error;
e=*(--S.top);
return 1;
}

void ClearStack(SqStack &S)
{
while(S.top!=S.base&&(*(S.top-1)!='\n'))
(--S.top);

}

void print(SqStack S)
{
char *p=S.base;
while(p!=S.top)
printf("%c",*p++);
}

int main()
{
char ch,e;
SqStack S;

InitStack(S);
ch=getchar();
while(ch!='~')
{
while( ch!='~')
{
switch(ch)
{
case'#':PopStack(S,*(S.top-1));break;
case'@':ClearStack(S);break;
default:PushStack(S,ch);break;
}
ch=getchar();
}
print(S);
ClearStack(S);
if(ch!='~')getchar();
}


return 0;
}


[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
2006-05-24 23:35
快速回复:EOF怎么用啊,看看我下面的程序哪的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017679 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved