hallo
i want 2 know if there is a function that reads from an input file and after reading this char will disapear.
i mean the read char will b disappeared.

Recommended Answers

All 10 Replies

Member Avatar for iamthwee

hallo
i want 2 know if there is a function that reads from an input file and after reading this char will disapear.
i mean the read char will b disappeared.

If not you could just write your own.

or can i read and write in the same file

Yes. You CAN read and wrte in the same file. You will have to use fstream to declare your stream.

http://www.daniweb.com/tutorials/tutorial6542.html

You will have to read the file into memory, change it there and then write it back if you want the read character to be deleted.

how i can read the file in memory
i want the char 2 b saved in memory not a copy

You have to copy everything after your character into an array or something, then come back and overwrite the character. Did you get me?

I think you need a clearer definition of what you want. characters don't just "disappear" -- unless your a magician.

Post an example of what you want. For example, if the word "hello" is read, do you want to delete the two 'l's and make it "heo"?

for ex:
here is my input file ack=100 , and i want 2 read the four chars ack= and then after reading the input file will b as shown 100

Member Avatar for iamthwee

for ex:
here is my input file ack=100 , and i want 2 read the four chars ack= and then after reading the input file will b as shown 100

I don't no what you mean? :sad:
What is ack?

>then after reading the input file will b as shown 100
Files are persistent, they don't work like that. If you want a destructive read, you'll need to build it yourself by rewriting the file. Since that's an expensive operation, you'll want to seriously consider whether you really need this feature or not.

for ex:
here is my input file ack=100 , and i want 2 read the four chars ack= and then after reading the input file will b as shown 100

If I understand you, you want to put the value 100 into an integer variable:?: If that is true, you have a couple options:
(1) use sscanf(), or (2) pointer parsing. There are other options in c++ using stringstream class.

char buf[20];
int n;
// read a line into buf is not shown
//buf[] = "ack=100"; after read
//
sscanf(buf,"ack=%d",&n); // now n == 100

(2) parse with a pointer

char buf[20];
char* ptr;
int n;
// read a line into buf is not shown
//buf[] = "ack=100"; after read
//
ptr = strchr(buf,'='); // locate the '=' symbol
n = atoi(ptr+1); // convert remainder to int
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.