?? filltable.c
字號:
/*FileName:FillTable.c*/
/*Write by Yata*/
/*2005.11.20*/
#include<stdio.h>
#define TRUE 1
#define FALSE 0
#define length 8 /*The length of array!*/
typedef struct
{
int code; /*The code of the word!*/
char content[length]; /*The content of the word!*/
}myword;
myword symbol[100];
int j;
int noerror; /*Is anything wrong?*/
int count=0; /*The number of different kinds of words!*/
int allinput=0; /*Record the number of words has inputed!*/
int found(char tofind[])
{
int i;
int result=FALSE;
allinput=allinput+1;
for(i=0;i<count;i++)
if(strcmp(symbol[i].content,tofind)==0)
result=TRUE;
return result;
}
void yata_puti(int i,FILE *fp) /*Input a integer into file!*/
{
char a,b;
a=i/10;
b=i%10;
if(a!=0)
fputc(a+48,fp);
fputc(b+48,fp);
}
void yata_fputs(char s[],FILE *fp) /*把s字符串輸入到fp文件上*/
{
int i;
for(i=0;i<length;i++)
{
if(s[i]==0)
fputc(' ',fp);
else
fputc(s[i],fp);
}
}
void fillintotable(FILE *fi,FILE *fo)
{
char ch;
char tempword[length];
int i=0;
int m,over_while;
noerror=TRUE;
over_while=FALSE;
strcpy(tempword,"");
ch=fgetc(fi);
while(ch!=EOF)
{
if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
{
if(i>=8)
{
fputs("Error:Over length error!\n",fo);
noerror=FALSE;
break;
}
else
{
tempword[i]=ch;
i=i+1;
}
}
else if(ch>='0'&&ch<='9')
{
if(i>=8)
{
fputs("Error:Over length error!\n",fo);
noerror=FALSE;
break;
}
if(i==0)
{
fputs("Error:Digit first error!\n",fo);
noerror=FALSE;
break;
}
else
{
tempword[i]=ch;
i=i+1;
}
}
else
{
switch(ch)
{
case ',':if(!found(tempword))
{
for(m=i;m<length;m++)
tempword[i]=0;
strcpy(symbol[count].content,tempword);
symbol[count].code=1+count;
count=count+1;
}
strcpy(tempword,"");
i=0;
break;
case ';':ch=fgetc(fi);
if(ch!=EOF)
{
fputs("Error:There are more than 2 ';'!\n",fo);
noerror=FALSE;
over_while=TRUE;
}
else if(!found(tempword))
{
for(m=i;m<length;m++)
tempword[i]=0;
strcpy(symbol[count].content,tempword);
symbol[count].code=1+count;
count=count+1;
}
break;
default:
{
noerror=FALSE;
over_while=TRUE;
fputs("Error:Illegal input symbol!\n",fo);
}
}
if(over_while==TRUE)
break;
}
ch=fgetc(fi);
}
}
void printid(FILE *fo)
{
int i;
fputs("There are ",fo);
yata_puti(allinput,fo);
fputs(" symbols inputed,and there are ",fo);
yata_puti(count,fo);
fputs(" different symbols!\n",fo);
fputs("The different symbols and according codes are as follow:\n",fo);
for(i=0;i<count;i++)
{
yata_puti(symbol[i].code,fo);
fputs(" ",fo);
yata_fputs(symbol[i].content,fo);
fputc('\n',fo);
}
}
void main()
{
FILE *fo;
FILE *fi;
fi=fopen("F:\\C\\read.txt","r");
fo=fopen("F:\\C\\write.txt","w");
fillintotable(fi,fo);
fclose(fi);
if(noerror==TRUE)
printid(fo);
fclose(fo);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -