cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) (04/09/90)
Well, I don't know if TC provides a function to determine the length
of the file, but you can certainly use ftell() to find your current
position and something similar to the following to determine the length
of the file if it doesn't (and the following should be portable to all
C compilers - it will certainly work on anything that accepts ANSI C).
#include <stdio.h>
long filelength (FILE *fp)
{
long current_position = ftell (fp);
long length_of_file;
fseek (fp, 0, SEEK_END);
length_of_file = ftell (fp);
fseek (fp, current_position, SEEK_SET);
return length_of_file;
}
Please excuse any typos ...
--
More half-baked ideas from the oven of:
****************************************************************************
Stephen M. Dunn cs4g6ag@maccs.dcss.mcmaster.ca
<std_disclaimer.h> = "\nI'm only an undergraduate ... for now!\n";
mefarimani@lion.waterloo.edu (Mehran E. Farimani) (04/10/90)
In article <26201F3B.1118@maccs.dcss.mcmaster.ca> cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) writes: > > Well, I don't know if TC provides a function to determine the length >of the file, but you can certainly use ftell() to find your current >position and something similar to the following to determine the length >of the file if it doesn't > ............... There are routines in both TC and MSC that do a file spec search (with pattern matching) in a directory. I think the names are something like "findfirst" and "findnext" for TC and "_dos_find_first" and "_dos_find_next" for MSC. These routines merely use an INT 21 service. Anyhow, every filename that matches the spec gets most of its directory info such as file size and date put into a structure. So you can check the appropriate fields for whatever purpose you need. This is also much more efficient that "fopen"ing a file, "fseek"ing to the end, "ftell"ing the position, and then "fclose"ing it. Mehran
weeks@ssbell.IMD.Sterling.COM (John Weeks) (04/13/90)
In article <26201F3B.1118@maccs.dcss.mcmaster.ca> cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) writes: > > Well, I don't know if TC provides a function to determine the length >of the file, There is a function in TC to determine the length of a file based on the file handle. Its something like getfilesize(), and returns the size in bytes as a long. If you opened the file with fopen(), there is a function to get the handle for the file, again I don't remember exactly what the function name is, something like gethandle() or filehandle() :-). Hope this helps. -- John Weeks Phone: (402) 291-8300 Sterling Software FSG/IMD e-mail: uunet!ssbell!weeks 1404 Ft. Crook Rd. South e-mail: weeks@ssbell.IMD.Sterling.COM