Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

fread(3s) [v7 man page]

FREAD(3S)																 FREAD(3S)

NAME
fread, fwrite - buffered binary input/output SYNOPSIS
#include <stdio.h> fread(ptr, sizeof(*ptr), nitems, stream) FILE *stream; fwrite(ptr, sizeof(*ptr), nitems, stream) FILE *stream; DESCRIPTION
Fread reads, into a block beginning at ptr, nitems of data of the type of *ptr from the named input stream. It returns the number of items actually read. Fwrite appends at most nitems of data of the type of *ptr beginning at ptr to the named output stream. It returns the number of items actually written. SEE ALSO
read(2), write(2), fopen(3), getc(3), putc(3), gets(3), puts(3), printf(3), scanf(3) DIAGNOSTICS
Fread and fwrite return 0 upon end of file or error. FREAD(3S)

Check Out this Related Man Page

FREAD(3S)																 FREAD(3S)

NAME
fread, fwrite - buffered binary input/output SYNOPSIS
#include <stdio.h> fread(ptr, sizeof(*ptr), nitems, stream) FILE *stream; fwrite(ptr, sizeof(*ptr), nitems, stream) FILE *stream; DESCRIPTION
Fread reads, into a block beginning at ptr, nitems of data of the type of *ptr from the named input stream. It returns the number of items actually read. If stream is stdin and the standard output is line buffered, then any partial output line will be flushed before any call to read(2) to satisfy the fread. Fwrite appends at most nitems of data of the type of *ptr beginning at ptr to the named output stream. It returns the number of items actually written. SEE ALSO
read(2), write(2), fopen(3S), getc(3S), putc(3S), gets(3S), puts(3S), printf(3S), scanf(3S) DIAGNOSTICS
Fread and fwrite return 0 upon end of file or error. 4th Berkeley Distribution May 15, 1985 FREAD(3S)
Man Page

8 More Discussions You Might Find Interesting

1. Programming

Using fread if the buffer size is not known

Hi... I am trying to read a binary data that have different types of messages of different lengths. I am using fread() but this functions needs the size and count to read the buffer from the file. I think this may cause that the buffer overlaps other messages. Is there an alternative to read... (1 Reply)
Discussion started by: jlrodz
1 Replies

2. Programming

fread64 fwrite64 compilation problem (undefined symbol)

I use a standard C source to access large files in a 32 bit environment. I've replaced fopen, fwrite and fread by fopen64, fwrite64 and fread64. First I did a test only replacing fopen by fopen64, it compiled without any other changes to my compilation options. The program crashed on a write, as... (3 Replies)
Discussion started by: Isax50
3 Replies

3. Programming

problem in reading file using fread

Hi All, These are the two ways i tried to read file but i getting work with second one not with the first. char buf; // Defining space for buf ctrlfnum = fopen(filename_arr.control_fname,"r"); 1) n = fread(buf,sizeof(buf),1,ctrlfnum); ============== (not works) 2) n =... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

4. Programming

fread: segementation fault(coredump) w/o stdlib.h

Hello All, I tried to test a sample fread example to read a complete file and the code is #include <stdio.h> #include <stdlib.h> int main () { FILE * pFile; long lSize; char * buffer; size_t result; pFile = fopen ( "test.xml" , "rb" ); if (pFile==NULL) {fputs ("File... (11 Replies)
Discussion started by: quintet
11 Replies

5. Programming

erase fread 's internal buffer ?

When fread is used twice, the second time it seems to overwrite the first time's output. Is there any way to clear fread's internal buffer after each use ? char *FILEREAD(const char *FILENAME) { static char READBUFFER = ""; READBUFFER = '\0'; // try to solve the problem but this will not... (2 Replies)
Discussion started by: limmer
2 Replies

6. Programming

Atomic Read and Write with stdio

hi guys. can we use fread and fwrite with pipes to write data more than PIPE_BUF atomically since they lock FILE object until I/O operation finish? (1 Reply)
Discussion started by: majid.merkava
1 Replies

7. Programming

What happens fwrite/fread at the same time?

Hello, I have a question about what happens when I copy the file which is being written by another process on Solaris 9/SPARC, UFS file system. in particular, I want to know what happens while some process is reading the file using fread or mmap, another process try to write something on the... (4 Replies)
Discussion started by: wipe3out
4 Replies

8. Programming

Malloc problem with fread() to read file to structure in C

Hello, I am trying to read a text file into linked list, but always got the first and last records wrong. 1) The problem looks related to the initialization of the node temp with malloc(), but could not figure it out. No error/warning at compiling, though. 2) The output file is empty,... (10 Replies)
Discussion started by: yifangt
10 Replies