473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to update and delete particular record

please say how to update a particular record and delete particular record from the following code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. struct cust
  5. {
  6.     char name[40];
  7.     char details[40];
  8. };
  9. int main()
  10. {
  11.     struct cust c;
  12.     FILE*fp;
  13.     char custname[20],choice,s;
  14.  
  15.     while(1)
  16.     {
  17.  
  18.         printf("1.enter customer details.\n");
  19.         printf("2. search for customer details .\n");
  20.         printf("3. exit.\n");
  21.         printf("enter ur choice\n");
  22.         choice=getchar();
  23.         switch(choice)
  24.             {
  25.             case '1':
  26.                     fp=fopen("cust.txt","ab");
  27.                     while (1)
  28.                     {
  29.                       printf("enter customer name:\n");
  30.                       scanf("%s",c.name);
  31.                       fflush(stdin);
  32.                       printf("\nenter details:");
  33.                       scanf("%s",c.details);
  34.                       fwrite(&c,sizeof(c),1,fp);
  35.                       fflush(stdin);
  36.                       printf("\n\ndo u wnt to continue(Y/N)");
  37.                       scanf("%s",&s);
  38.                       if(s=='n'||s=='N')
  39.                             break;
  40.                     }
  41.                     fclose(fp);
  42.                     break;
  43.      case '2':
  44.                     fp=fopen("cust.txt","rb");
  45.                     printf("enter customer name:\n");
  46.                     scanf("%s",custname);
  47.                     while(fread(&c,sizeof(c),1,fp))
  48.                     {
  49.                         if(strcmp(custname,c.name)==0)
  50.                         {
  51.                             printf("\n\t %s\t %s",c.name,c.details);
  52.                             getchar();
  53.                             break;
  54.                         }
  55.                         else
  56.                         {
  57.                             printf("no details founnd:\n");
  58.                         }
  59.                     }
  60.                     fclose(fp);
  61.                     getchar();
  62.                     break;
  63.             case '3':
  64.                     exit(0);
  65.         }
  66.     }
  67.     getchar();
  68. }
Oct 31 '12 #1
1 3276
weaknessforcats
9,208 Expert Mod 8TB
You are using a file. What does delete mean? The file has the records already written.

Do you intend to copy file file up to the deleted record and then skip the deleted record and then copy the file back to the original? Assuming you can find the record to be deleted.

Do you intend to overwrite the deleted record with coded characters, like 032 or 003 and then access the file with functions that are smart enough to skip over these "deleted" characters. This would also assume a compress function to squeeze the deleted characters out of the file usually by making copy of the file by skipping over these characters.

Does your file have the correct format? As in is it a text file where all records contain characters or is it a compressed file where you have embedded start/stop characters for each record?

All of this means that you cannot process a file unless you know how it was written and what rules were used to put the data in the file.
Oct 31 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: news.la.sbcglobal.net | last post by:
hi all i am trying to update or delete a row/record in table cptcodes the error i am getting is key column information is insufficient or incorrect to many rows were affected by update.... ...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
7
by: Garry Newman | last post by:
From what I can gather these commands are automatically generated throught the OleDbDataAdapter wizard when working with a one table database and from the MSDN documnetation the values shown on...
0
by: HS1 | last post by:
Hello all I have a DataGrid1 presenting records of a table ("clients") in a Access Database through a DataSet (ds) using DataAdapter (da1) and buttons "add", "save" and"delete" buttons with the...
0
by: Murali | last post by:
In MsAccess project I Create the Link table with Sqlserver 2000. I am facing the multiuser Problem in my application. The problem describes below: If one user is updating one record and at that...
3
subashini Thiyagarajan
by: subashini Thiyagarajan | last post by:
<% Dim adoCon Dim rsDeleteEntry Dim strSQL Dim lngRecordNo lngRecordNo = CLng(Request.QueryString("ID")) lngRecordNo1 = CLng(Request.QueryString("ID"))
5
by: agarwasa2008 | last post by:
Hi, I would like to delete a record based on a user entered string. Here are the details. I have a txtFind textbox. A string is entered by the user. Based on that string value it displays that...
3
by: Constantine AI | last post by:
Hi i am trying to DELETE a Record if the details do not exist within a table. Here is my code below; Dim strSQL As String Dim strSQL2 As String Dim Reply As String Dim db As...
10
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I...
2
by: ellenr | last post by:
I have a 600 record mysql db. It has a timestamp field, auto incr id field, several varchar fields and several smallint fields. The id field is set as primary key. The access03 has a form...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.