C: Question on file handling

  • #1
208
1

Homework Statement


How to delete specific record from a text file by some field from struct?

Homework Equations


-File handling
-Searching algorithms

The Attempt at a Solution


I know that one of the searching algorithms is needed, but could someone explain how to
delete found record from file?
 

Answers and Replies

  • #2
35,045
6,782

Homework Statement


How to delete specific record from a text file by some field from struct?

Homework Equations


-File handling
-Searching algorithms

The Attempt at a Solution


I know that one of the searching algorithms is needed, but could someone explain how to
delete found record from file?
Here's what I would do:
While the applicable field is not found:
1. Read each record from the file into memory.
2. If the field you're looking for does NOT match the value you're looking for, write the record to the file; otherwise (not a match) don't do anything.
 
  • Like
Likes sysprog
  • #3
1
1
Hi,
You can do this by simply read the records from the file and start writing it to another file while doing that check read data matches the data to be deleted. If matched then ignore it continue reading the file and writing to another file. At the end delete the file we read and rename the file we written as old one.
For your references
Fopen in c [1] [2]
fgetc [1] [2]
fputc[1][2]
Fclose in c [1] [2]
Please reply If you want me to write the code for you.
Thanks regards.
 
  • Like
Likes sysprog
  • #4
1,961
1,209
Please reply If you want me to write the code for you.
Hi @rusahupe, it's nice of you to want to help out ##-## I'm not a Mentor/Moderator here, but given that you're new here, I'd like to gently point out that there are rules on the Physics Forums that place some carefully-thought-out limits on how members may help with homework, and it seems to me that simply writing the code for someone, without first seeing a genuine attempt from that someone, might be out of bounds ##-## you can read the rules at the Terms link in the footer of every page, and if you're unsure about something, you can PM one of the Mentors . . .
 
  • Like
Likes rusahupe and berkeman

Related Threads on C: Question on file handling

Replies
0
Views
1K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
15
Views
3K
  • Last Post
Replies
22
Views
2K
  • Last Post
Replies
2
Views
984
Replies
4
Views
2K
  • Last Post
Replies
14
Views
1K
Top