void process(PriceFile* price_file) { ItemRecord *item_record_ptr; ItemRecord new_record; char ascii_code_number[100]; int status; char upc[11]; char description[100]; double temp_price; unsigned price; int i; int mode; int old_mode; char temp_string[100]; char temp2[100]; int field_length; mode = INPUT_MODE; old_mode = LOOKUP_MODE; for (i = 0; ; i ++) { if (mode == INPUT_MODE) { if (old_mode != INPUT_MODE) { printf("Now in INPUT mode.\n"); old_mode = INPUT_MODE; } printf("Please enter code number,\n"); printf("ENTER to switch to lookup mode,\n"); printf("or * to terminate the program.\n"); gets(temp_string); if (strcmp(temp_string,"*") == 0) break; if (strlen(temp_string) == 0) { mode = LOOKUP_MODE; continue; } field_length = strlen(temp_string); if (field_length > ASCII_KEY_SIZE) { printf("UPC code is a maximum of %d characters\n", ASCII_KEY_SIZE); continue; } else if (field_length < ASCII_KEY_SIZE) { memset(temp2,0,ASCII_KEY_SIZE+1); memset(temp2,'0',ASCII_KEY_SIZE-field_length); strcat(temp2,temp_string); strcpy(temp_string,temp2); } ascii_to_BCD(new_record.upc,temp_string,ASCII_KEY_SIZE); printf("Please enter description: "); gets(temp_string); field_length = strlen(temp_string); if (field_length > DESCRIPTION_CHARS) { printf("Description is a maximum of %d characters\n", DESCRIPTION_CHARS); continue; } ascii_to_radix40((unsigned int *)new_record.description, (unsigned char *)temp_string, DESCRIPTION_CHARS); printf("Please enter price: "); gets(temp_string); temp_price = atof(temp_string); if (temp_price > 655.35) { printf("Price too large - limit is $655.35\n"); continue; } new_record.price = (unsigned)(100*temp_price); status = write_record(price_file,new_record); if (status == FILE_FULL) { printf("Cannot add entry for item #%s to file\n", new_record.upc); break; } else if (status == FOUND) printf("Item #%s already in file\n",new_record.upc); } else { if (old_mode != LOOKUP_MODE) { printf("Now in LOOKUP mode.\n"); old_mode = LOOKUP_MODE; } printf("Please enter code number: "); gets(temp_string); if (strcmp(temp_string,"*") == 0) break; if (strlen(temp_string) == 0) { mode = INPUT_MODE; continue; } field_length = strlen(temp_string); if (field_length > ASCII_KEY_SIZE) { printf("UPC code is a maximum of %d characters\n", ASCII_KEY_SIZE); continue; } else if (field_length < ASCII_KEY_SIZE) { memset(temp2,0,ASCII_KEY_SIZE+1); memset(temp2,'0',ASCII_KEY_SIZE-field_length); strcat(temp2,temp_string); strcpy(temp_string,temp2); } strcpy(ascii_code_number,temp_string); status = lookup_record(price_file,ascii_code_number, &item_record_ptr); if (status == FOUND) { BCD_to_ascii(upc,&item_record_ptr->upc[0],ASCII_KEY_SIZE); radix40_to_ascii((unsigned char *)description, &item_record_ptr->description[0], DESCRIPTION_CHARS); price = item_record_ptr->price; printf("%s:%s:%u\n",upc,description,price); } else if (status == NOT_IN_FILE) printf("Item #%s not found\n",ascii_code_number); } } }