Need help on Electronic Inventory System...

This is a discussion on Need help on Electronic Inventory System... within the C Programming forums, part of the General Programming Boards category; Hi guys, i new your help on my system which im stuck on how to remove a line of data ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Location
    Pekan, Malaysia
    Posts
    1

    Need help on Electronic Inventory System...

    Hi guys, i new your help on my system which im stuck on how to remove a line of data in the text.file & how to search the data based on the "Item_code" only

    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    int Choice,Item_Code,Item_Qty,year,Halogen,i;
    float Item_Price;
    char Item_name [21],Item_date [21],Item_Value [10], choose;
    
    
    int main ()
    {
    
    
    printf("\n*********************************************************");
    printf("\n**********Electronic Component Inventory System**********");
    printf("\n*********************************************************\n");
    
    
    printf("\nMain Menu");
    printf("\n---------");
    printf("\n1.Show All Component List");
    printf("\n2.Add Component");
    printf("\n3.Remove Component");
    printf("\n4.Search Item Inventory slot");
    printf("\n5.Exit");
    
    
    printf("\n\nPlease Choose your option:");
    scanf("%d",&Choice);
    
    
    switch (Choice)
    {
    case 1:
        printf("You have selected Show All Component List\n");
        FILE *f;
           f = fopen("test.txt","r");
    
    
           printf("\Code\tName\t\tValue\tPrice\tQty\tDate");
    
    
           while (fscanf (f," %d",&Item_Code) !=EOF){
        fscanf(f," %s", &Item_name);
        fscanf(f," %s", &Item_Value);
        fscanf(f," %f", &Item_Price);
        fscanf(f," %d", &Item_Qty);
        fscanf(f," %s", &Item_date);
        printf("\n%d\t%s\t%s\t%.2f\t%d\t%s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);}
        //{
        //printf("%d",Item_Code);
        //}
        fclose(f);
        break;
    case 2:
        print_item();
        for(i=0;i<5;i++){
        printf("\nDo you want to continue?Y/N = ");
        scanf(" %c", &choose);
        if(choose=='Y')
        print_item();
        else if(choose=='N')
        break;}
    case 3:
        printf("You have selected Remove Component\n");
    void search()
    {
      int sh;
          design();
          gotoxy(17,6);
          printf("\xDB\xDB\xB2  Two options available to search \xB2\xDB\xDB");
          gotoxy(15,9);
          printf("[ 1 ]  -  Search by ID number   .");
          gotoxy(15,11);
          printf("[ 2 ]  -  Search by Description .");
          gotoxy(17,15);
          printf("Enter your choice:: ");
          sh=toupper(getch());
    
    
      switch(sh)
      {
        case '1':
        search_id();
        break;
    
    
        case '2':
        search_name();
        break;
    
    
        default:
        gotoxy(18,18);
        printf("\a\xDB\xDB wrong entry try again");
        getch();
       }
      getche();
    
    
    }
    
    
        break;
    case 4:
        printf("You have selected Search Item Inventory Slot\n");
        break;
    case 5:
        printf("You have selected Exit\n");
        break;
    default:
        printf("Invalid option selected\n");
    }
    return 0;
    }
    
    
    void print_item()
    {
        FILE *f;
        printf("You have selected Add Component\n");
        f = fopen("test.txt","a");
    
    
        printf("Enter your Item Code :");
        scanf ("\n %d",&Item_Code);
         printf("Item Code = %d Recorded\n",Item_Code);
    
    
         printf("Enter your Item Name :");
         scanf ("\n %s",&Item_name);
         printf("Item Name = %s Recorded\n",Item_name);
    
    
        printf("Enter your Item Value :");
         scanf ("\n %s",&Item_Value);
         printf("Item Value = %s Recorded\n",Item_Value);
    
    
    printf("Enter your Item Price :");
         scanf ("\n %f",&Item_Price);
         printf("Item Name = RM %.2f Recorded\n",Item_Price);
    
    
        printf("Enter your Item Qty :");
        scanf ("\n %d",&Item_Qty);
         printf("Item Qty = %d Recorded\n",Item_Qty);
    
    
        printf("Enter your Item Date :");
        scanf ("\n %s",&Item_date);
         printf("Item Date = %s Recorded\n",Item_date);
    
    
        fprintf(f,"\n%d\t%s\t%s\t%.2f\t%d\t%s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);
        //fprintf(f,"\n%d %s %s %.2f %d %s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);
        fclose(f);
    
    
        f = fopen("test.txt","r");
        printf("\nItem Code Item Name Item Code Item Date");
    
    
           while (fscanf (f," %d",&Item_Code) !=EOF){
        fscanf(f," %s", &Item_name);
        fscanf(f," %s", &Item_Value);
        fscanf(f," %f", &Item_Price);
        fscanf(f," %d", &Item_Qty);
        fscanf(f," %s", &Item_date);
    
    
        printf("\n%d\t%s\t%s\t%.2f\t%d\t%s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);}
        //printf("\n%d %s %s %.2f %d %s",Item_Code,Item_name,Item_Value,Item_Price,Item_Qty,Item_date);}
        fclose(f);
        return 0;
    
    
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It's a little crude, but you don't have fixed length records to work with (records equals structs in C. Record field equals struct member in C in case you're wondering).

    For right now, the best way to remove an items from the inventory, is to read in the file, and write out each item to a new temp file. When you find the item you want to delete, don't write out that item to the temp file, and continue writing out all the other items into the temp file. Now close both files, and delete the old inventory file, and rename the temp file, the inventory file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How should i make a inventory system for my text adventure?
    By Nathan the noob in forum Game Programming
    Replies: 7
    Last Post: 03-12-2010, 07:21 PM
  2. Inventory System
    By headshot119 in forum C Programming
    Replies: 28
    Last Post: 09-24-2009, 11:53 AM
  3. a couple questions about inventory management system
    By Rubiks14 in forum Game Programming
    Replies: 1
    Last Post: 05-20-2009, 10:27 AM
  4. inventory system
    By linucksrox in forum Game Programming
    Replies: 0
    Last Post: 04-19-2006, 02:19 PM
  5. Thoughts on Menu System for Book Inventory
    By curlious in forum C++ Programming
    Replies: 3
    Last Post: 09-29-2003, 04:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21