70,035
社区成员
发帖
与我相关
我的任务
分享
//这是我以前写的,不知道楼主是不是这个意思?
//----------------------------------------------------------
//d盘下的my picture文件夹,比如里面包括:1.jpg,2.jpg,1.txt这三个文件
//1.txt里面的内容为:
//1.jpg *********
//2.jpg *********
//3.jpg *********
//4.jpg *********
//----------------------------------------------------------
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<io.h>
#include <process.h>
#include <memory.h>
void SearchFile(const char *);
int main()
{
printf("在.txt文件里查找.jpg文件:\n\n");
SearchFile("d:\\my picture");
printf("\n");
system("pause");
return 0;
}
void SearchFile(const char *dir)
{
FILE *fp;
char *str="aa";
char buff[256];
fp=fopen("d:\\my picture\\1.txt","r");
if (fp==NULL)
{
printf("can not oepn file\n");
}
struct _finddata_t ffblk;
char path[256];
sprintf(path,"%s\\*.jpg*",dir);
long done = _findfirst(path,&ffblk);
int find=0;
while (find==0)
{
if(strcmp(ffblk.name,".jpg"))
{
while(fgets(buff,256,fp)!=NULL)
{
if (strstr(buff,ffblk.name)!=NULL)
{
printf("%s",buff);
memset(buff,0,256);
}
}
fseek(fp,0,0);
}
find=_findnext(done,&ffblk);
}
_findclose(done);
printf("\n");
fclose(fp);
}