Ver検索のバージョンアップ版

指定したディレクトリ内のファイルの中身を検索し、

Verという文字がファイルにあれば、その一番したのVerを出す。

 

[root@gochamaze C]# cat directory.c
#include <stdio.h>
#include <dirent.h>
#include <string.h>

#define BUF 256

int main(void)
{

DIR *dp;
FILE *rfp;
struct dirent *dir;
char *path = "/root/test/";
char buf[BUF];
char buf2[BUF];
char filename[BUF];
char *sp;
int count = 0;
int count2 = 0;

if *1 == NULL) {

fprintf(stderr,"ERROR");
}

while *2 != NULL ){

while(fgets(buf2,BUF,rfp)){
if *3 != NULL ) {
count++;

}

}


}


fclose(rfp);


strcpy(filename,buf);

rfp = fopen(filename,"r");

while(fgets(buf2,BUF,rfp)) {
count2++;
if ( count == count2 ) {
printf("%s",buf2);
}
}


}

 


}

*1:dp = opendir(path

*2:dir = readdir(dp))) {

sprintf(buf,"%s%s",path,dir->d_name);

if ((rfp = fopen(buf,"r"

*3:sp = strstr(buf2,"Ver"