[問題] 擷取檔案名稱後只想輸出前段字元
開發平台(Platform): Win10
編譯器:Dev-C++
問題(Question):
小弟目前是C初學者,我想請教版上各位先進。
我目前想要把文件中的檔案名稱擷取前面幾個字元建立成一份清單,
但是不知道該怎麼做,目前想法是應該把字串轉為字元。
btw,檔案名稱為:20110827001040.00.led.01.00-03.00h.jpg
想擷取為20110827001040.00.led.01.00-03.00h
這是我的程式碼:
/*Program*/
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
int main()
{
FILE *fout;
fout=fopen("output.txt","w+t");
if(fout==NULL){
printf("Fail to open file output!\n");
return:
}
struct _finddata_t fileinfo;
long fHandle;
int i=0;
if((fHandle=_findfirst("*.jpg",&fileinfo))==-1L){
printf("no jpg\n");
return 0;
}
else{
do{
i++;
fprintf(fout,"%s\n",fileinfo.name);
}while(_findnext(fHandle,&fileinfo)==0);
}
_findclose(fHandle);
fclose(fout);
system("pause");
return 0;
}
感謝QQ
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.134.82 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1605275636.A.6DD.html
→
11/13 22:24,
3年前
, 1F
11/13 22:24, 1F
→
11/13 22:24,
3年前
, 2F
11/13 22:24, 2F
→
11/13 22:46,
3年前
, 3F
11/13 22:46, 3F
→
11/13 23:31,
3年前
, 4F
11/13 23:31, 4F
→
11/13 23:31,
3年前
, 5F
11/13 23:31, 5F
→
11/14 16:55,
3年前
, 6F
11/14 16:55, 6F
→
11/14 16:55,
3年前
, 7F
11/14 16:55, 7F
→
11/14 17:10,
3年前
, 8F
11/14 17:10, 8F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):