void findrefs(region r, void *from, void *to) { char *f; if (!out) out = fopen("/dev/tty", "w"); for (f = PALIGN(from, PTRALIGNMENT); f < (char *)to; f += PTRALIGNMENT) if (regionof(*(void **)f) == r) printref(f); fflush(out); }
END_TEST START_TEST(test_make_lower) { char strs[][4][20] = {{ "oNe", "TWO", "three", "Four" }, { "ALPHA", "beta", "Gamma", "Theta" }}; char ref[][4][20] = {{ "one", "two", "three", "four" }, { "alpha", "beta", "gamma", "theta" }}; const unsigned int num = 4; for (int k = 0; k < 2; k++) { char **arr = init_array(); if(!arr) { fail("[Task 4.3.c] init_array returned NULL"); } for (unsigned int i = 0; i < num; i++) { char **a2 = add_string(arr, strs[k][i]); if (!a2) { free_strings(arr); fail("[Task 4.3.c] add_string returned NULL"); } arr = a2; } char buf[200]; printref(buf, strs[k], num); make_lower(arr); for (unsigned int i = 0; i < num; i++) { if (strcmp(arr[i], ref[k][i])) { remove_nonascii(arr[i]); char buf2[200]; sprintf(buf2, "[Task 4.3.c] After adding strings {%s}, array member %d is '%s', should be '%s'", buf, i, arr[i], ref[k][i]); free_strings(arr); fail(buf2); } } free_strings(arr); } }
void addentry(){ int i, s; /*Setting border color */ init_pair(2,COLOR_MAGENTA,COLOR_BLACK); attron(COLOR_PAIR(2)); border(0,0,0,0, 0,0,0,0); refresh(); attroff(COLOR_PAIR(2)); refresh(); int fict, sh, ref, nonfict; FILE *fp; Book book; char option = 'y'; clear(); refresh(); while(option == 'y' || option == 'Y') { printgen(); scanw("%d",&s); switch(s) { case FICTION : printfiction(); scanw("%d",&fict); fp=fopen("Fiction.dat","ab+"); if(getinfo(&book)){ book.cat = categories[s - 1]; book.subcat = fiction[fict - 1]; fseek(fp,0,SEEK_END); fwrite(&book,sizeof(book),1,fp); fclose(fp); } break; case NONFICTION : fp=fopen("Nonfiction.dat","ab+"); if(getinfo(&book) == 1){ book.cat = categories[s-1]; book.subcat = categories[s-1]; fseek(fp,0,SEEK_END); fwrite(&book,sizeof(book),1,fp); fclose(fp); } break; case REFERENCE : printref(); scanw("%d",&ref); fp=fopen("Reference.dat","ab+"); if(getinfo(&book) == 1){ book.cat = categories[s-1]; book.subcat = refer[ref - 1]; fseek(fp,0,SEEK_END); fwrite(&book,sizeof(book),1,fp); fclose(fp); } break; case SELFHELP : printselfhelp(); scanw("%d",&sh); fp=fopen("Selfhelp.dat","ab+"); if(getinfo(&book) == 1){ book.cat,categories[s-1]; book.subcat = selfhelp[sh - 1]; fseek(fp,0,SEEK_END); fwrite(&book,sizeof(book),1,fp); fclose(fp); } break; case MENU : mainmenu(); return; break; default : printw("\n ----- Wrong option. Please select again -----\n"); addentry(); return; } mvaddstr(10,16,"The record is sucessfully saved"); mvaddstr(11,16,"Add more ? (y/n) "); option = getch(); } mvaddstr(12,16,"Press Enter to go to main menu"); getch(); mainmenu(); refresh(); return; }