I need to read the first KB of each file inside a folder, I can show the names of all the files on the screen but then I can not figure out what to do to read each file one by one
#include <stdio.h>
#include <stdlib.h>
#include "antispam.h"
#include <sys/types.h>
#include <dirent.h>
int main(int argc, char *argv[])
{
/* Variables */
DIR *dirp;
struct dirent *direntp;
if(argc != 2){
printf("Argumentos invalidos\n");
exit(1);
}else{
/* Abrimos el directorio */
dirp = opendir(argv[1]);
if (dirp == NULL){
printf("Error: No se puede abrir el directorio\n");
exit(2);
}
/* Leemos las entradas del directorio */
while ((direntp = readdir(dirp)) != NULL) {
/* FILE *f = fopen(direntp->d_name, "r");*/
printf("%s\n",direntp->d_name);
}
/*
printf("numero de argumentos %d\n",(int)argc);
printf("argumento 1 %s\n",argv[0]);
printf("argumento 2 %s\n",argv[1]);
*/
/* Cerramos el directorio */
closedir(dirp);
}
return 0;
}