On Fri, Feb 26, 2010 at 5:19 PM, Michael Robinson
<[email protected]>wrote:

> I'm trying to write a simple C program to open a text file with
> temperature data in it, extract the highest, the lowest, and the
> last temperature, and write that information to another text file.
>
> How in C do I verify that the files I'm working with are text files?
> Specifically since I don't allow clobbering, I'm worried about the
> input file.
>
> I'm thinking there is a UNIX file command which I should be able
> to call from inside the C program, but is there a better way?
>

I don't think there is a simple way to do what you want to do in C,
generally.  The *nix command line utility 'file' goes through an extended
series of tests to determine file type, incuding as a last resort (as Bill
mentioned) actually examining the file in an attempt to determine the
character set (not all 'text' character sets are the same).  If the data in
the file is in some regular format, you could approximate this by doing a
pre-examination of the file before you use it, to try and determine if the
things you think are there really are there. Alternatively, you could issue
a 'file' command from your code (using popen, for example), and read the
results.

- tony
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to