Sponsored Content
Full Discussion: help with fseek
Top Forums Programming help with fseek Post 302344363 by jim mcnamara on Sunday 16th of August 2009 06:41:23 AM
Old 08-16-2009
read the whole file into a buffer, then print each character in the buffer back to front:
Code:
#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[i]);
	free(p);	
}

there is no error checking in this code...
 

3 More Discussions You Might Find Interesting

1. Programming

error when using fseek() function

The errors EBADF & ESPIPE occur at this fseek call. Does anybody know how to solve this problem? Thanks in advance. toFileStream=fdopen(localFileDes,"ra+"); if(fseek(toFileStream, 0, SEEK_END)!=0){ if(errno==EBADF) printf("errno==EBADF\n"); if(errno==EINVAL)... (3 Replies)
Discussion started by: ivancheung
3 Replies

2. Programming

q on fseek() & ftell() + tga files

In determining the true file size of a .tga file is the fseek(fptr,0,SEEK_END); file_size = ftell(fptr); combination reliable ? The reason Im asking is because the value of file_size is in agreement with doing a wc -c mytga.tga however when I get the value of the extension... (2 Replies)
Discussion started by: JamesGoh
2 Replies

3. Programming

help with reading a binary file and fseek

this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong? #include <stdio.h> typedef struct { char name; int number; float balance; } acct_info_t; int main (int... (0 Replies)
Discussion started by: bjhum33
0 Replies
explain_fseek_or_die(3) 				     Library Functions Manual					   explain_fseek_or_die(3)

NAME
explain_fseek_or_die - reposition a stream and report errors SYNOPSIS
#include <libexplain/fseek.h> void explain_fseek_or_die(FILE *fp, long offset, int whence); int explain_fseek_on_error(FILE *fp, long offset, int whence); DESCRIPTION
The explain_fseek_or_die function is used to call the fseek(3) system call. On failure an explanation will be printed to stderr, obtained from the explain_fseek(3) function, and then the process terminates by calling exit(EXIT_FAILURE). The explain_fseek_on_error function is used to call the fseek(3) system call. On failure an explanation will be printed to stderr, obtained from the explain_fseek(3) function, but still returns to the caller. fp The fp, exactly as to be passed to the fseek(3) system call. offset The offset, exactly as to be passed to the fseek(3) system call. whence The whence, exactly as to be passed to the fseek(3) system call. RETURN VALUE
The explain_fseek_or_die function only returns on success, see fseek(3) for more information. On failure, prints an explanation and exits, it does not return. The explain_fseek_on_error function always returns the value return by the wrapped fseek(3) system call. EXAMPLE
The explain_fseek_or_die function is intended to be used in a fashion similar to the following example: explain_fseek_or_die(fp, offset, whence); SEE ALSO
fseek(3) reposition a stream explain_fseek(3) explain fseek(3) errors exit(2) terminate the calling process COPYRIGHT
libexplain version 0.52 Copyright (C) 2010 Peter Miller explain_fseek_or_die(3)
All times are GMT -4. The time now is 03:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy