C語言根據后綴判斷文件類型


//判斷文件類型為pdf或者word類型
#include<stdio.h> #include<string.h> 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; }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM