| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 507 人关注过本帖
标题:[求助]不知道怎么不能运行!
只看楼主 加入收藏
knight110
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2006-4-13
收藏
 问题点数:0 回复次数:3 
[求助]不知道怎么不能运行!

#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#define NULL 0

FILE *fp;
char cbuffer;
char *key[8]={"if","else","for","while","do","return","break","continue"};
char *border[6]={",",";","{","}","(",")"};
char *arithmetic[4]={"+","-","*","/"};
char *relation[6]={"<","<=","=",">",">=","<>"};
char *consts[20];
char *label[20];
int constnum=0,labelnum=0;
int search(char searchchar[],int wordtype)
{
int i=0;
switch (wordtype) {
case 1:for (i=0;i<=7;i++)
{
if (strcmp(key[i],searchchar)==0)
return(i+1);
}
case 2:{for (i=0;i<=5;i++)
{
if (strcmp(border[i],searchchar)==0)
return(i+1);
} return(0);
}

case 3:{for (i=0;i<=3;i++)
{
if (strcmp(arithmetic[i],searchchar)==0)
{
return(i+1);
}
}
return(0);
}

case 4:{for (i=0;i<=5;i++)
{
if (strcmp(relation[i],searchchar)==0)
{
return(i+1);
}
}
return(0);
}

case 5:{for (i=0;i<=constnum;i++)
{
if (strcmp(consts[i],searchchar)==0)
{
return(i+1);
}
}
consts[i-1]=(char *)malloc(sizeof(searchchar));
strcpy(consts[i-1],searchchar);
constnum++;
return(i);
}

case 6:{for (i=0;i<=labelnum;i++)
{
if (strcmp(label[i],searchchar)==0)
{
return(i+1);
}
}
label[i-1]=(char *)malloc(sizeof(searchchar));
strcpy(label[i-1],searchchar);
labelnum++;
return(i);
}

}


}
char alphaprocess(char buffer)
{
int atype;
int i=-1;
char alphatp[20];
while ((isalpha(buffer))||(isdigit(buffer)))
{
alphatp[++i]=buffer;
buffer=fgetc(fp);
}
alphatp[i+1]='\0';
if (atype=search(alphatp,1))
printf("%s (1,%d)\n",alphatp,atype-1);
else
{
atype=search(alphatp,6);
printf("%s (6,%d)\n",alphatp,atype-1);
}
return(buffer);
}
char digitprocess(char buffer)
{
int i=-1;
char digittp[20];
int dtype;
while ((isdigit(buffer)))
{
digittp[++i]=buffer;
buffer=fgetc(fp);
}
digittp[i+1]='\0';
dtype=search(digittp,5);
printf("%s (5,%d)\n",digittp,dtype-1);
return(buffer);
}
char otherprocess(char buffer)
{

int i=-1;
char othertp[20];
int otype,otypetp;
othertp[0]=buffer;
othertp[1]='\0';
if (otype=search(othertp,3))
{
printf("%s (3,%d)\n",othertp,otype-1);
buffer=fgetc(fp);
goto out;
}

if (otype=search(othertp,4))
{
buffer=fgetc(fp);
othertp[1]=buffer;
othertp[2]='\0';
if (otypetp=search(othertp,4))
{
printf("%s (4,%d)\n",othertp,otypetp-1);
goto out;
}
else
othertp[1]='\0';
printf("%s (4,%d)\n",othertp,otype-1);
goto out;
}

if (buffer==':')
{
buffer=fgetc(fp);
if (buffer=='=')
printf(":= (2,2)\n");
buffer=fgetc(fp);
goto out;
}
else
{
if (otype=search(othertp,2))
{
printf("%s (2,%d)\n",othertp,otype-1);
buffer=fgetc(fp);
goto out;
}
}

if ((buffer!='\n')&&(buffer!=' '))
printf("%c error,not a word\n",buffer);
buffer=fgetc(fp);
out: return(buffer);
}
void main()
{
int i;
for (i=0;i<=20;i++)
{
label[i]=NULL;
consts[i]=NULL;
};

{
if((fp=fopen("f:example.c","r"))==NULL)
printf("error\n");
else
cbuffer = fgetc(fp);
while (cbuffer!=EOF)
{
if (isalpha(cbuffer))
cbuffer=alphaprocess(cbuffer);
else if (isdigit(cbuffer))
cbuffer=digitprocess(cbuffer);
else cbuffer=otherprocess(cbuffer);
}
printf("over\n");
getchar();
}
}

搜索更多相关主题的帖子: 运行 
2006-04-13 18:48
rellorsky
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-14
收藏
得分:0 

#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#define NULL 0

FILE *fp;
char cbuffer;
char *key[8]={"if","else","for","while","do","return","break","continue"};
char *border[6]={",",";","{","}","(",")"};
char *arithmetic[4]={"+","-","*","/"};
char *relation[6]={"<","<=","=",">",">=","<>"};
char *consts[20];
char *label[20];
int constnum=0,labelnum=0;
int search(char * searchchar,int wordtype)
{
int i=0;
switch (wordtype) {
case 1:for (i=0;i<=7;i++)
{
if (strcmp(key[i],searchchar)==0)
return(i+1);
}
case 2:{for (i=0;i<=5;i++)
{
if (strcmp(border[i],searchchar)==0)
return(i+1);
} return(0);
}

case 3:{for (i=0;i<=3;i++)
{
// if (strcmp(arithmetic[i],searchchar)==0)
{
return(i+1);
}
}
return(0);
}

case 4:{for (i=0;i<=5;i++)
{
// if (strcmp(relation[i],searchchar)==0)
{
return(i+1);
}
}
return(0);
}

case 5:{
for (i=0;i<=constnum;i++)
{
// if (strcmp(consts[i],searchchar)==0)
{
return(i+1);
}
}
consts[i-1]=(char *)malloc(sizeof(searchchar));
strcpy(consts[i-1],searchchar);
constnum++;
return(i);
}

case 6:{for (i=0;i<=labelnum;i++)
{
// if (strcmp(label[i],searchchar)==0)
{
return(i+1);
}
}
label[i-1]=(char *)malloc(sizeof(searchchar));
strcpy(label[i-1],searchchar);
labelnum++;
return(i);
}

}


}
char alphaprocess(char buffer)
{
int atype;
int i=-1;
char alphatp[20];
while ((isalpha(buffer))||(isdigit(buffer)))
{
alphatp[++i]=buffer;
buffer=fgetc(fp);
}
alphatp[i+1]='\0';
if (atype=search(alphatp,1))
printf("%s (1,%d)\n",alphatp,atype-1);
else
{
atype=search(alphatp,6);
printf("%s (6,%d)\n",alphatp,atype-1);
}
return(buffer);
}
char digitprocess(char buffer)
{
int i=-1;
char digittp[20];
int dtype;
while ((isdigit(buffer)))
{
digittp[++i]=buffer;
buffer=fgetc(fp);
}
digittp[i+1]='\0';
dtype=search(digittp,5);/////
printf("%s (5,%d)\n",digittp,dtype-1);
return(buffer);
}
char otherprocess(char buffer)
{

int i=-1;
char othertp[20];
int otype,otypetp;
othertp[0]=buffer;
othertp[1]='\0';
if (otype=search(othertp,3))
{
printf("%s (3,%d)\n",othertp,otype-1);
buffer=fgetc(fp);
goto out;
}

if (otype=search(othertp,4))
{
buffer=fgetc(fp);
othertp[1]=buffer;
othertp[2]='\0';
if (otypetp=search(othertp,4))
{
printf("%s (4,%d)\n",othertp,otypetp-1);
goto out;
}
else
othertp[1]='\0';
printf("%s (4,%d)\n",othertp,otype-1);
goto out;
}

if (buffer==':')
{
buffer=fgetc(fp);
if (buffer=='=')
printf(":= (2,2)\n");
buffer=fgetc(fp);
goto out;
}
else
{
if (otype=search(othertp,2))
{
printf("%s (2,%d)\n",othertp,otype-1);
buffer=fgetc(fp);
goto out;
}
}

if ((buffer!='\n')&&(buffer!=' '))
printf("%c error,not a word\n",buffer);
buffer=fgetc(fp);
out: return(buffer);
}
void main()
{
int i;
for (i=0;i<=20;i++)
{
label[i]=NULL;
consts[i]=NULL;
};

{
if((fp=fopen("example.cpp","r"))==NULL)
printf("error\n");
else
cbuffer = fgetc(fp);
while (cbuffer!=EOF)
{
if (isalpha(cbuffer))
cbuffer=alphaprocess(cbuffer);
else if (isdigit(cbuffer))
cbuffer=digitprocess(cbuffer);
else
cbuffer=otherprocess(cbuffer);
}
printf("over\n");
getchar();
}
}



这样该一下代码可以运行!
不过请在该工程目录下加一个example.cpp文件
里边放一些c代码

[此贴子已经被作者于2006-4-14 16:07:26编辑过]

2006-04-14 16:06
knight110
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2006-4-13
收藏
得分:0 
请问怎么在工程目录下加example.cpp文件.谢谢!

2006-04-15 07:11
knight110
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2006-4-13
收藏
得分:0 

首先感谢帮忙,我把那个.CPP改成.C能运行,但是为什么这条语句
a>=x10.0.5+5.0会出现这样的结果,
x10 <6,0>
10不是常量吗?怎么会识别不出来,这位大哥,有QQ吗,加QQ聊吧,我的是359175536


2006-04-15 07:40
快速回复:[求助]不知道怎么不能运行!
数据加载中...
 
   



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

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