Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************/
- /** 20141230 Exam 11 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/12/30 am.11:30 **/
- /**************************************/
- #include <stdio.h>
- #include <stdlib.h>
- struct Items{
- int number_id;
- char item[10];
- int price;
- char firm[10];
- };
- struct Members{
- int number_id;
- char name[10];
- char address[10];
- char phone[15];
- int items_quantity[100];
- };
- int CheckFile()
- {
- FILE *fptrCheck;
- //Check ItemsData
- if((fptrCheck = fopen("ItemsData.txt", "r")) == NULL)
- return 0;
- //Check Member
- else if((fptrCheck = fopen("MembersData.txt", "r")) == NULL)
- return 1;
- //Check Bill
- else if((fptrCheck = fopen("BillsData.txt", "r")) == NULL)
- return 2;
- else
- return 3;
- }
- int main(int argc, char const *argv[])
- {
- switch(CheckFile())
- {
- case 0:
- printf(" ---- ERROR read file: ItemsData.txt ----\n");
- return 0;
- case 1:
- printf(" ---- ERROR read file: MembersData.txt ----\n");
- return 0;
- case 2:
- printf(" ---- ERROR read file: BillsData.txt ----\n");
- return 0;
- case 3:
- {
- //Read ItemsData.txt
- struct Items All_Item[100];
- FILE *fptrReadFile = fopen("ItemsData.txt", "r");
- int item_counter = 0;
- while(!feof(fptrReadFile))
- {
- fscanf(fptrReadFile, "%d %s %d %s\n", &All_Item[item_counter].number_id, All_Item[item_counter].item, &All_Item[item_counter].price, All_Item[item_counter].firm);
- item_counter++;
- }
- fclose(fptrReadFile);
- //Read MembersData.txt
- struct Members All_Member[100];
- fptrReadFile = fopen("MembersData.txt", "r");
- int member_counter = 0;
- while(!feof(fptrReadFile))
- {
- fscanf(fptrReadFile, "%d %s %s %s\n", &All_Member[member_counter].number_id, All_Member[member_counter].name, All_Member[member_counter].address, All_Member[member_counter]. phone);
- member_counter++;
- }
- fclose(fptrReadFile);
- //Read Bill and throw it in the struct array
- fptrReadFile = fopen("BillsData.txt", "r");
- while(!feof(fptrReadFile))
- {
- int member_id = 0, item_id = 0, quantity = 0;
- fscanf(fptrReadFile, "%d %d %d\n", &member_id, &item_id, &quantity);
- All_Member[member_id].items_quantity[item_id] += quantity;
- }
- fclose(fptrReadFile);
- while(1)
- {
- system("cls");
- printf("Which user pay list do you want to see: ");
- int _select = 0;
- scanf("%d", &_select);
- if(_select == -1)
- return 0;
- else if(_select > member_counter)
- {
- printf(" ---- DO NOT HAVE THIS USER ID ----\n\n");
- system("pause");
- continue;
- }
- else
- {
- printf("Name\tAddress\tPhone\tItem\tFirm\tPrice\tQuantity\tLump_Sum\n");
- for(int i = 0; i < 100; i++)
- if(All_Member[_select].items_quantity[i] > 0)
- printf("%s\t%s\t%s\t%s\t%s\t%d\t%d\t\t%d\n", All_Member[_select].name, All_Member[_select].address, All_Member[_select].phone, All_Item[i].item, All_Item[i].firm, All_Item[i].price, All_Member[_select].items_quantity[i], All_Item[i].price * All_Member[_select].items_quantity[i]);
- printf("\n");
- system("pause");
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment