資源簡介
一個txt文檔的詞庫,c寫的一個電子詞典程序
代碼片段和文件信息
#include?
#include?
#include?
struct?word
{
char*?english;
char*?chinese;
int?flag;
struct?word*?next;
};
void?user_error(char*?src)
{
printf(“%s\n“src);
exit(-1);
}
struct?word*?init(void)
{
struct?word*?ptr?=?(struct?word*)malloc(sizeof(struct?word));
if(NULL==ptr)
{
user_error(“ptr?error“);
}
memset(ptr0sizeof(struct?word));
}
struct?word?listword(struct?word*?tstFILE*?txt)
{
if(tst==NULL?&&?txt==NULL)
{
user_error(“listword?error“);
}
int?ret;
int?out=-1;
int?etr=0;
char?tmp[1];
char*?arr?=?(char*)malloc(1024*sizeof(char));?
char*?name=?(char*)malloc(100*sizeof(char));?
struct?word*ptr?=(struct?word*)malloc(sizeof(struct?word));
if(ptr==NULL)
{
user_error(“ptr?error“);
}
ret?=?fread(namesizeof(char)1txt);
while(1)
{
out++;
fread(name+outsizeof(char)1txt);
if(name[out]==‘\n‘)
{
fread(arrsizeof(char)6txt);
while(1)
{
fread(arr+etrsizeof(char)1txt);
if(arr[etr]==‘\n‘)
{
ret?=?fread(tmpsizeof(char)1txt);
ptr->flag?=?ret;
break;
}
etr++;
}
ptr->chinese=?arr;
goto?loop;
}
}
loop:?fseek(txt-1SEEK_CUR);
??ptr->english=?name;
??return?*ptr;
}
void?creat(struct?word*?pheadstruct?word*?list)
{
if(phead==NULL?||?list==NULL)
{
user_error(“creat?error“);
}
struct?word*?one?=?phead;
struct?word*?second?=?list;
struct?word*?three?=?one->next;?
struct?word*?tmp?=?(struct?word*)malloc(sizeof(struct?word));
if(tmp?==?NULL)
{
user_err
評論
共有 條評論