C++/reading a file in reverse order
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.
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.
---------- FOLLOW-UP ----------
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.
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.