Hi everyone!
I am making a program in C where the user will input a month then the program prints out all the names of files created in that month. Right now I'm having trouble in printing the names of files. Here's a portion of my code. Can you help me figure out what's wrong with it?
int main (void)
{
int month;
scanf("%d", month);
DIR *da;
struct dirent *ep;
time_t temp;
struct tm *foo = localtime(&temp);
struct stat attrib;
da = opendir ("./");
if (da != NULL)
{
while (ep = readdir (da))
while ((ep = readdir (da)) != NULL)
{
const size_t len = strlen(ep->d_name);
if (len > 4 &&
ep->d_name[len - 4] == '.' &&
ep->d_name[len - 3] == 't' &&
ep->d_name[len - 2] == 'x' &&
ep->d_name[len - 1] == 't') {
stat(ep->d_name, &attrib);
foo = localtime(&(attrib.st_mtime));
month = foo->tm_mon + 1;
if(month == 1) {
printf ("%s\n", ep->d_name);
}
else if(month == 2) {
printf ("%s\n", ep->d_name);
}