资源简介
一个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
评论
共有 条评论