why do I have "file size exceed" problem?

G

guru.slt

my c program fails to write file that is bigger than 2G bytes. I used
gcc compiler. After writing for a while, It says: "filesize limit
exceed". How to solve this?

But, if I compile the c code by "c++", then it can write more than 2G
bytes in a file. Where is the problem for "gcc"?

the code is here:
---------------------------
#include <stdio.h>
#include <string.h>

int main()
{
char buffer[2281];

FILE* f_p;
f_p = fopen("output.vi", "w");

int i;
for (i = 0; i < 2280; ++i) buffer = 'a';
buffer = '\n';

while(1)
fwrite(buffer, 1, 2281, f_p);

}
------------------------------
 
S

Sorav Bansal

my c program fails to write file that is bigger than 2G bytes. I used
gcc compiler. After writing for a while, It says: "filesize limit
exceed". How to solve this?

Use the following flag while compiling your program:
"-D_FILE_OFFSET_BITS=64". eg. gcc -D_FILE_OFFSET_BITS=64 foo.c -o foo

This allows any file opened in the C program to be of size upto 2^63-1
which is much larger than any disk ever produced. This is provided that
your OS supports large files (which seems to be the case since you said
the c++ compiler supports large files)

Sorav
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top