|
发表于 2015-4-26 08:14:24
|
显示全部楼层
}
break;
}
if(choice == 'Y')break;
}
for(;;)
{
printf("\\n是否为顶点?(Y/N)\\n");
scanf("%s" , &choice);
choice = toupper(choice);
if(choice == 'N')
{
printf("\\n请输入对新对象的描述\\n");
scanf("%s" , feature);
for(i = 0 ; i < nodenum ; i++)
{
ntx = nodelink;
if(strstr(feature , ntx->feature)!=NULL)
{
newl = (struct SUBLINK*) malloc (sizeof(sublink));
if(newl == NULL)
{
printf("\\n内存不够!\\n");
exit(0);
}
if(newnode->upnnum == 0)
newnode->upnode = endl = newl;
newl->index = i;
endl->next = newl;
endl = newl;
newl->next = NULL;
newnode->upnnum++;
///////////////////////////////将信息写入父节点
newl = (struct SUBLINK*) malloc (sizeof(sublink));
if(newl == NULL)
{
printf("\\n内存不够!\\n");
exit(0);
}
if(ntx->sonnum == 0)
ntx->sonnode = endl = newl;
newl->index = nodenum;
newl->next = ntx->sonnode;
ntx->sonnode = newl;
ntx->sonnum++;
}
}
break;
}
if(choice == 'Y')break;
}
nodelink[nodenum] = newnode;
nodenum++;
}
void store()
{
int i , j;
char s[10];
FILE *kf;
struct NODE *writenode;
struct SUBLINK *newlink , *oldlink;
if((kf = fopen("knowledgestore.txt" , "w")) == NULL)
{
printf("Cannot create/open file");
exit(1);
}
fprintf(kf , "%5d" , nodenum);
for(i = 0 ; i < nodenum ; i++)
{
writenode = nodelink;
fprintf(kf , "%20s" , writenode->feature);
fprintf(kf , "%5d" , writenode->upnnum);
newlink = writenode->upnode;
for(j = 0 ; j < writenode->upnnum ; j++)
{
fprintf(kf , "%5d" , newlink->index);
oldlink = newlink;
newlink = newlink->next;
free(oldlink);
}
fprintf(kf , "%5d" , writenode->type);
fprintf(kf , "%5d" , writenode->sonnum);
newlink = writenode->sonnode;
for(j = 0 ; j < writenode->sonnum ; j++)
{
fprintf(kf , "%5d" , newlink->index);
oldlink = newlink;
newlink = newlink->next;
free(oldlink);
}
free(writenode);
}
strcpy(s , "end");
fprintf(kf , "%10s" , s);
fclose(kf);
exit(0);
}
int showfault()
{
char choice;
for(;;)
{
printf("是否继续?(Y/N)\\n");
scanf("%s" , &choice);
while(choice == '10');
choice = toupper(choice);
if(choice == 'Y')return 1;
if(choice == 'N')exit(0);
}
} |
|