Solved

FILE I/O

Posted on 1999-01-19
9
186 Views
Last Modified: 2010-04-15
What is the maximum possible size for a text file that is to be used as a log file? And how do I go about exceeding the file size limitation?

The file size that I had get is 662KB and after which the program terminates the logging. My code is as follows:

BOOL LogFile(int line, char *smsg, char *rmsg)
{

      FILE *fp;
      static int i=1;
      char time_buf[30];
      time_t cur_time;
      int call_line;

      call_line=(line+2)/2;

      time(&cur_time);
      strcpy(time_buf,asctime(localtime(&cur_time)));
      time_buf[strlen(time_buf)-1]='\0';
      
      if((fp=fopen("SOCKlog.txt","at"))==  NULL)
            //t"))==  NULL)
      {
            printf("Error encountered!");
            exit(1);
      }
fprintf(fp,"%s %ld %s %s %s %d ** %-10s %-10s %-10s %-10s \n","No.", i++,"Date/Time:",time_buf,"Line:",call_line,"(smsg):",smsg," (rmsg):",rmsg);

      fclose(fp);
      return TRUE;
      
}

What could be the problem?
0
Comment
Question by:Meng
9 Comments
 

Author Comment

by:Meng
ID: 1258183
Can U include the library functions that is accountable for exceeding this limitation?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1258184
This is operating system dependant.

Typically you will find the max file size is 2^32, 2^64, 2^31 or 2^63 bytes, depending on what platform you're running on
0
 
LVL 1

Expert Comment

by:MCoroli
ID: 1258185
To exceed you can analize file size and create another one. Old file can be renamed. Not very nice but simple way
0
 
LVL 11

Expert Comment

by:alexo
ID: 1258186
Since you posted it in the "C" area, the C functions fseek() and lseek() accept a "long" offset.  Therefore, they cannot work with files longer than LONG_MAX (as defined in LIMITS.H for your compiler).
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Expert Comment

by:Mithander
ID: 1258187
I havn't heard of a limitation on file size.  But I could belive it is operating system dependant.  Just yesterday I made a text file that was two hundred meg big.  I did it on accident, (A loop that never terminated.) but I don't think you would need a file bigger than that.  I did that under Win95.  What errors are you getting? can you post some code?
0
 

Author Comment

by:Meng
ID: 1258188
Edited text of question
0
 
LVL 84

Expert Comment

by:ozo
ID: 1258189
perror("fopen failed because:");

the disk may have run out of space,
or you may have a user quota, or process limit set
0
 

Expert Comment

by:yingchunli
ID: 1258190
I havn't heard of a limitation on file size either.  You are using C and possiblly using integer as iondex to count or deal with bytes of the buffer.  If the integer is 16 bites (Max value ~65k) on your platform, it may cause (index) problem when file size is over 65k.
0
 
LVL 3

Accepted Solution

by:
mliberi earned 10 total points
ID: 1258191
there is no implicit limitation on the size of a text file, so your code should happily run on many os platforms.

please consider the following causes for your error:

1) your system manager configured your user account so that you cannot create a file bigger than ..... bytes. You can check for such a limitation, among others, with the command "ulimit -a" (are you running on a UNIX platform?"

2) your file filled the filesystem

3) if disk quotas has been configured, you could have exceeded your disk quota even if the filesystem is not full.

In any case the best thing you can do is putting a "perror" call just before exit(1). That would print an error message about the kind of error that occurred
0

Featured Post

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Directory does exist 19 144
mixing C++ and C code elegantly 10 153
List out all word 7 257
convert char array to number in c 5 83
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now