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.
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.
FILE *fp = fopen( "myfile", "rb" );
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;
if( x )
printf("Unusable file. Terminating.");