C C 讀取判斷檔案字尾名

2021-09-05 12:15:52 字數 472 閱讀 3569

通過判斷dot的位置獲取讀入檔案的字尾名,並使其與指定的字尾名進行對比,一致時返回真值,只使用簡單的字元陣列操作。

bool decide_ext(char *gname,char *nsuff)

// gname: name of the given file

// nsuff: suffix you need

; int c;

int j = 0;

c = strlen(gname);

std::cout<< c << '\n';

for(int i = 0; iint k = j;

j = c - j - 1;

for(int i = 0; iif (0==strcmp(suff,nsuff))

return true;

else

return false;

}

字尾名判斷演算法

字尾名判斷演算法 採用mfc框架的cstring可以非常快速完成,但如果採用的是標準c 則沒那麼直接方便.下面是乙個判斷字尾名的演算法,絕對不是效率最高的,也絕對不是最嚴謹的,但可能是比較簡單易懂的.bool checkextendname const char pszstr,const char ...

擷取檔案字尾名

擷取給的檔名的字尾名 在這裡要注意可能出現的檔案是否有字尾名,例如.abc和abc.其實這兩種是沒有字尾名的,所以判斷切片 的索引位置必須有所限制 def foo filename,has dot false 獲取檔名的字尾名 param filename 檔名 param has dot 字尾名是...

獲取檔案字尾名

獲取到filename的字尾 利用lastindexof 從最後面截字尾,找到最後乙個點的索引然後加一,利用substring擷取該索引後的字串 f.getfilename substring f.getfilename lastindexof 1 lastindexof 方法有以下四種形式 pub...