//判断文件类型为pdf或者word类型 #include#include int File(char *Filename);int main(int argc, char *argv[]){ char Filename[40]; memset(Filename,0x00,sizeof(Filename)); strcpy(Filename,argv[1]); printf("%s",Filename); // NULL => not file type printf("12------%d",File(Filename)); if(File(Filename) == 1 ){ printf("The file is type of word or pdf"); } else{ printf("The file is not type of word or pdf"); }}int File(char *Filename){ int flag = 0; // 0->NOT 1->yes char str[6]; memset(str,0x00,sizeof(str)); //.doc .docx .pdf if( strncmp(Filename,".doc",4) == 0 || strncmp(Filename,".docx",5) == 0 || strncmp(Filename,".pdf",4) == 0) { printf("line of 31————%s",Filename); flag = 0; return flag; } strncpy(str,Filename+(strlen(Filename))-4,4); printf("line of 33————%s",str); if( strncmp(str,".doc",4) == 0 ||strncmp(str,".pdf",4)== 0 ) { flag = 1; } memset(str,0x00,sizeof(str)); printf("line of 40————%s",str); strncpy(str,Filename+(strlen(Filename))-5,5); if( strncmp(str,".docx",5) == 0 ) { flag = 1; } return flag;}