hi everyone,
I am going to code a program for visit files in a directory. Follows are my codes:
#include <ftw.h>
#include <string.h>
#include <stdio.h>
int fn(const char *file, const struct stat *sb, int flag, struct FTW *s)
{
FILE *fp;
char line[128+1];
int count =0;
if( flag==FTW_F ){
if(strstr(file,"status")!=NULL){
fp = fopen(file,"r");
fgets(line, sizeof(line), fp);
fclose(fp);
printf("%s", line);
}
}
return 0;
}
int main()
{
int result;
nftw("/proc/", fn, 100, FTW_MOUNT);
return 1;
}
When I compiled it using "gcc test.c", it printed out the following messages:
'struct FTW' declared inside parameter list
error: 'FTW_MOUNT' undeclared (first use in this function)
Does anybody know what happen about these codes? I know these definitions are in the file "ftw.h" already, why these errors come out?
Do I need to link some lib?
Waiting for you help! Thanks in advance.