Thread: how to delete in c

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    20

    how to delete in c

    I have written a simple database program that stores products. this database has a few functions one of them is a delete function. this delete function's job is to delete a certain product.

    example is my inputs are:

    Varunummer: ......Namn ---------------Lagersaldo
    覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
    123 ..................majs .......................12



    and if i choose to delete a product the result will be as in below:

    but i have tried everything but nothing works. the closest i have gotten to fully delete a product has been as in below
    Varunummer: ...............Namn ....................Lagersaldo
    覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
    0 .................................................. ....................0

    varunummer and lagersaldo is zero but i have managed to delete the name of the product. but i want everything to disappear.

    translation:
    varunummer=productnumber
    lagersaldo=productbalance
    namn=name
    antal_varor=nrofproducts

    this is my delete function:


    Code:
    void radera(int antal_varor, struct storagemanipulation *inventory)
    {
    int i, varunummer;
    
    printf("du har valt att avregistrera en vara\n");
    soka(antal_varor,inventory);
    
    printf("Ange varunumret som du vill avregistrera?\n");
    scanf("%d",&varunummer);
    i=find_part(varunummer, antal_varor, inventory);
    
    for(i = antal_varor - 1;i < varunummer-1;i++)
    {
    
    inventory[i].varunummer = inventory[i+1].varunummer;
    *inventory[i].namn = *inventory[i+1].namn;
    inventory[i].lagersaldo = inventory[i+1].lagersaldo;
    antal_varor--;
    }
    
    }

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,106
    Maybe something like this. You'll have to pass the first parameter as a pointer so it can be updated.
    Code:
    void radera(int *antal_varor,
                struct storagemanipulation *inventory)
    {
      int i, varunummer;
    
    
      printf("du har valt att avregistrera en vara\n");
      soka(*antal_varor, inventory);
     
      printf("Ange varunumret som du vill avregistrera?\n");
      scanf("%d", &varunummer);
      i = find_part(varunummer, *antal_varor, inventory);
    
    
      // You should check that varunummer was valid, then...
    
    
      --*antal_varor;  
      for ( ; i < *antal_varor; i++)
        inventory[i] = inventory[i + 1];
    }
    The best argument against democracy is a five minute conversation with the average voter. - Churchill

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    20
    Thaaaank u soooo much man. U dont understand how much i have put into fixing that issue.
    Dude u are awesome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-07-2017, 01:10 PM
  2. List - Why my delete function doesn't delete?
    By juanjuanjuan in forum C Programming
    Replies: 7
    Last Post: 12-09-2014, 10:10 PM
  3. Concerning delete/delete[] at program exit
    By laserlight in forum C++ Programming
    Replies: 58
    Last Post: 01-09-2008, 01:40 PM
  4. Replies: 17
    Last Post: 11-16-2006, 09:06 PM
  5. using delete to delete an array
    By iain in forum C++ Programming
    Replies: 2
    Last Post: 03-11-2002, 03:53 PM

Tags for this Thread