help with fseek

Hi,

I working a c project in IBM AIX. I have a requirement like this.

I have some contents in *temp. I am writing the contents of *temp to a file pointer ftemp (*ftemp for an tmp file tmpfile.txt)

Now I want to read the contents of *ftemp in the reverse order an dneed to print it in the screen.

say if *temp="979899", in ftemp also it will be 979899. From ftemp I need to read the file from the reverse direction. For that I used fseek as below

fseek(ftemp,0,SEEK_END) - this will place the pointer at the end. Now how to read it till the beginning, which function to use.. The contents from ftemp should be read in reverse directiona nd need to be printed in stdout.

Please help me, this is a kind of urgent requirement.

Thx in advance.

read the whole file into a buffer, then print each character in the buffer back to front:

#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>

void backward(FILE *in)
{
	size_t len=0;
	char *p=NULL;
	int i=0;
	struct stat st;
	
	fstat(fileno(in), &st);
	len=st.st_size;
	p=calloc(1, len + 1);
	rewind(in);
	fread(p, 1, len, in);
	for(i=len ; i; i--)
		printf("%c\n", p);
	free(p);	
}

there is no error checking in this code...

Thank you Jim