C++/reading a file in reverse order
Expert: Joydeep Bhattacharya - 3/9/2008
QuestionQUESTION: 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
AnswerHi 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