#include
#include
#include
#include
#include
#include
#include
#include"stdint.h"
int main()
{
int lenth = 20;
int n = 3 ;
int bl ;
int i = 0 ;
int isgbk(char * , int );
char test[100];
int fp ;
fp = open("/temp/GBKtext.txt",O_RDONLY);
if( fp!= 1 )
{
i = read(fp,test,lenth);
if( i >=0 )
puts("readfile succese");
else{
puts("readfile failed ");
exit(0);
}
}
else{
puts("openfile failed");
return 0;
}
close(fp);
bl = isgbk(test , n );
if( 1 == bl )
printf("This file is gbkfile");
else printf("This file is not gbkfile");
return 0;
}
int isgbk(char *test , int n )
{
if( n>2 &&(uint8_t)*test>=0x81 && (uint8_t)*test<=0xfe
&& (
((uint8_t)*(test+1)>=0x80 && (uint8_t)*(test+1)<=0x7e)
||((uint8_t)*(test+1)>=0xa1 && (uint8_t)*(test+1)<=0xfe)
)
)
return 1;
else return 0;
}
wdsr90 于 2011-10-18 09:37:30发表:
没人顶,自己顶,呵呵……:0wpoi2