Im trying to count the types of files inputted into a program. So if you enter echo.c its a C source, echo.h is Header and so on. But if you input a directory, like echo/root
it should count as an directory
type but right now its counting as a exe
type. Ive gotten everything else working, im just trying to figure out how to use stat()
to check if the argv
is a directory.
Heres what I have so far:
#include <sys/stat.h>
int main(int argc, char* argv[]){
int cCount = 0;
int cHeadCount = 0;
int dirCount = 0;
for(int i = 1; i < argc; i++){
FILE *fi = fopen(argv[i], "r");
if(!fi){
fprintf(stderr,"File not found: %s", argv[i]);
}
else{
struct stat directory;
//if .c extension > cCount++
//else if .h extension > cHeadCount++
else if( stat( argv[i], &directory ) == 0 ){
if( directory.st_mode & S_IFDIR ){
dirCount++;
}
}
}
//print values, exit
}
}