帮忙把C++改成C语言程序!

来源:百度知道 编辑:UC知道 时间:2024/07/08 17:25:05
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>
struct KeyWord{
char Keyword[20];
int count;
};

KeyWord KeywordTable[]=
{
{"else",0},{"switch",0},{"if",0},{"do",0},{"while",0},{"case",0}
};

int SeqSearch(KeyWord *tab,int n,char *word)
{
int i;
for(i=0;i<n;i++,tab++)
if(strcmp(word,tab->Keyword)==0)
return i;
return -1;
}

int Getword(ifstream &fin,char w[])
{
char c;
int i=0;
while(fin.get(c)&&!isalpha(c));
if(fin.eof())

你自己检查下算法:

#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>

typedef struct KeyWord{
char Keyword[20];
int count;
}KeyWord;

KeyWord KeywordTable[]=
{
{"else",0},{"switch",0},{"if",0},{"do",0},{"while",0},{"case",0}
};

int SeqSearch(KeyWord *tab,int n,char *word)
{
int i;
for(i=0;i<n;i++,tab++)
if(strcmp(word,tab->Keyword)==0)
return i;
return -1;
}

int Getword(FILE *fp,char w[])
{
char c;
int i=0;
while((c=fgetc(fp)) &&!isalpha(c))
{
if(feof(fp))
{
return 0;
}
}

w[i++]=c;
while((c = fgetc(fp)) &&(isalpha(c)||isdigit(c)))
{
w[i++]=c;
}

w[i]='\0';