/* ================================================================================== load Load the address file. ================================================================================== */ void load() { struct address *info; FILE *fp; fp = fopen("mlist", "rb"); if (!fp) { printf("Cannot open file.\n"); exit(1); } /* free any previously allocated memory */ while (start) { info = start->next; free(info); start = info; } /* reset top and bottom pointers */ start = last = NULL; printf("\nLoading File\n"); while (!feof(fp)) { info = (struct address *) malloc(sizeof(struct address)); if (!info) { printf("Out of Memory"); return; } if (1 != fread(info, sizeof(struct address), 1, fp)) break; dls_store(info, &start, &last); } fclose(fp); }
/* ================================================================================== enter Enter names and addresses. ================================================================================== */ void enter(void) { struct address *info; for (;;) { info = (struct address *)malloc(sizeof(struct address)); if (!info) { printf("\nout of memory"); return; } inputs("Enter name: ", info->name, 30); if (!info->name[0]) break; /* stop entering */ inputs("Enter street: ", info->street, 40); inputs("Enter city: ", info->city, 20); inputs("Enter state: ", info->state, 3); inputs("Enter zip: ", info->zip, 10); dls_store(info, &start, &last); } /* entry loop */ }
/*将文本插在指定行端部 */ int FileTest::enter(int linenum) { struct Line *info; char t[81]; for(;;) { /* */ info=(struct Line *)malloc(sizeof(struct Line)); if(!info){ printf("\t! 内存不够!\n"); return(NULL); } printf("%d:",linenum); gets(info->text); info->num=linenum; if(*info->text){ if(find(linenum)) patchup(linenum,1); if(*info->text) m_start=dls_store(info); } else break; linenum++; } return(linenum); }