In C, there is no difference between "text files" and "binary files" as far as it is concerned. (Not entirly true, since it does give you text mode and binary mode for opening a file.)
Basicly, you read a byte from the file, and check if it's a printable character. If it isn't, you're basicly looking at a binary file.
Code:
FILE *fp = fopen( "myfile", "rb" );
int c,x=0;
if( fp )
{
while( (c=fgetc(fp) != EOF )
if( !isprint(c) )
{
printf("This file contains unprintable characters, and as such, is likely binary.\n");
x = 1;
break;
}
fclose(fp);
}
if( x )
{
printf("Unusable file. Terminating.");
exit(0);
}
If x is not zero, you have a bad file, so you terminate the program. Otherwise, you reopen it in text mode and use it.
Quzah.