You are here:

C++/reading a file in reverse order

Advertisement


Question
QUESTION: hi,i have a question that i want to read a file (unknown size) in reverse order and write the contents in another file.
please help me.
thank you

ANSWER: hi salini

you question was really interesting for that copy the content of the original file in a temporary file during runtime and then read the temporary file.... this is the best solution i can find out at this moment will let you know if i can find some other method.

regards
Joydeep Bhattacharya
http://www.scodz.com

---------- FOLLOW-UP ----------

QUESTION: hi,
thank you for reply i have a question that if i want to print a file in reverse order by using the dynamic alocation of memory then how to do.
thank you


Answer
Hi Shalini

What you can do is take a char pointer and allocate it dynamically allocate memory

char *p = (char*)malloc(sizeof(char)*no_of_char_in_file);

Now store all the the characters of the file into the dynamically created array and then reverse the array using the simple process. I am sure this is gonna work fine and at a much better speed.

Do ask me if you are stuck with any problem.

regards
Joydeep Bhattacharya
http://www.scodz.com

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

TSR, Socket and Very Complex Mathematical Problem

Experience

Worked on many OOP projects with design patterns

Organizations
http://www.scodz.com

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Awards and Honors
Being a proud owner of a website of programming called http://www.scodz.com

Past/Present Clients
http://www.funforu.com http://www.dhoondho.com http://analysingc.50webs.com

©2016 About.com. All rights reserved.