Welcome to Dream.In.Code
Click Here
Getting C++ Help is Easy!

Join 117,570 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,777 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Deleting Info from a txt file

2 Pages V  1 2 >  
Reply to this topicStart new topic

Deleting Info from a txt file

webmin
post 19 Jul, 2008 - 07:16 AM
Post #1


D.I.C Head

**
Joined: 21 May, 2008
Posts: 95


My Contributions


I've learned how to write info to a txt file, but now I'd like to learn how to remove that info from the txt file

(I'm too lazy to go to the root of my hard drive and open the file and delete it)

What's even worse is I have launchy where I hit alt + space and I could type in the location of the file and open that way, but nah I'd rather do straight from the program.

My question is basically this, I'd like for the program to list all the records (which I already know how to do)
and then I'd like to be able to select a record based on the row, and delete it or modify it.

I need this preferably in C. Thanks
User is offlineProfile CardPM

Go to the top of the page


gabehabe
post 19 Jul, 2008 - 07:24 AM
Post #2


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 3,382



Thanked 69 times

Dream Kudos: 2175

Expert In: (X)HTML, CSS, Batch Scripting, C, C++

My Contributions


cpp
HAI
CAN HAS STDIO?
GIMMEH TEHCODEZ
VISIBLE "Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well."
KTHXBYE


Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM

Go to the top of the page

webmin
post 20 Jul, 2008 - 06:00 PM
Post #3


D.I.C Head

**
Joined: 21 May, 2008
Posts: 95


My Contributions


I'm sorry I want you to know that I'm not ignoring this post It's just that this was a little side project that I wanted to learn and I couldn't seem to find anything useful under google search using manipulating text files in C that seemed to describe what I wanted to do.

When I get more time, I'll see if I can play with my code a little and figure something close. Until then, if someone knows of a great resource that I could look at and point me in the right direction I'd be happy to take a look at it as long as it for C language.

Thanks.
User is offlineProfile CardPM

Go to the top of the page

nirvanarupali
post 20 Jul, 2008 - 09:30 PM
Post #4


"To think is to create"

Group Icon
Joined: 1 Aug, 2007
Posts: 962



Thanked 2 times

Dream Kudos: 375
My Contributions


You want to delete something in the file or delete the file?

Just search in the C++ snippets.
User is offlineProfile CardPM

Go to the top of the page

webmin
post 21 Jul, 2008 - 05:19 AM
Post #5


D.I.C Head

**
Joined: 21 May, 2008
Posts: 95


My Contributions


Something in the file...
User is offlineProfile CardPM

Go to the top of the page

KYA
post 21 Jul, 2008 - 09:58 AM
Post #6


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 3,087



Thanked 24 times

Dream Kudos: 1150
My Contributions


This snippet will guide the way:

File workings

cplusplus.com also has a great section on FILE input/output
User is offlineProfile CardPM

Go to the top of the page

Delta_Echo
post 21 Jul, 2008 - 10:03 PM
Post #7


D.I.C Regular

***
Joined: 24 Oct, 2007
Posts: 400


My Contributions


you could take the contents of the file, read it to an array, remove what needs to be removed, then write the array back to the file after you wipe the file contents.
User is offlineProfile CardPM

Go to the top of the page

webmin
post 24 Jul, 2008 - 04:21 PM
Post #8


D.I.C Head

**
Joined: 21 May, 2008
Posts: 95


My Contributions


QUOTE(Delta_Echo @ 22 Jul, 2008 - 01:03 AM) *

you could take the contents of the file, read it to an array, remove what needs to be removed, then write the array back to the file after you wipe the file contents.


That's perfect, because this is something I'll need to use in my next project. Can you point to a reference on how to do that? I've looked on cprogramming.com but I'm not really sure what to do here...
User is offlineProfile CardPM

Go to the top of the page

Delta_Echo
post 24 Jul, 2008 - 10:17 PM
Post #9


D.I.C Regular

***
Joined: 24 Oct, 2007
Posts: 400


My Contributions


Tutorials: (on C++ File I/O (Input/Output)
http://www.cplusplus.com/doc/tutorial/files.html
http://www.cprogramming.com/tutorial/lesson10.html

User is offlineProfile CardPM

Go to the top of the page

Delta_Echo
post 24 Jul, 2008 - 11:37 PM
Post #10


D.I.C Regular

***
Joined: 24 Oct, 2007
Posts: 400


My Contributions


Oh, if your just starting C+, i suggest you buy "C++ Without Fear". Its a great book.
User is offlineProfile CardPM

Go to the top of the page

webmin
post 25 Jul, 2008 - 05:31 AM
Post #11


D.I.C Head

**
Joined: 21 May, 2008
Posts: 95


My Contributions


Again this is all great info, but I'm not onto learning C++ yet. I'm still learning C. If anyone knows of any resources that are written for C I'd appreciate it. Thanks.
User is offlineProfile CardPM

Go to the top of the page

polymath
post 25 Jul, 2008 - 09:06 AM
Post #12


D.I.C Regular

Group Icon
Joined: 4 Apr, 2008
Posts: 390



Thanked 4 times

Dream Kudos: 500
My Contributions


OK. IFF you want to read info into an array then rewrite it, you need to open it in truncation mode if you are using fstream with c++.


ofstream fout;
fout.open("file.txt", fstream::trunc);
//writing here overwrites the file
fout.close();
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 10/7/08 08:23PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month