write a program to display all the files from the current
directory which are created in particular month
Answer Posted / rakesh
#include<stdio.h>
#include<stddef.h>
#include<dirent.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<time.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
char in[100],st[100],*ch,*ch1,c,buff[512];
DIR *dp;
int i;
struct dirent *ep;
struct stat sb;
char mon[100];
dp=opendir("./");
if(dp!=NULL)
{
while(ep=readdir(dp))
{
if(stat(ep->d_name,&sb)==-1)
{
perror("stat");
exit(EXIT_SUCCESS);
}
strcpy(mon,ctime(&sb.st_ctime));
ch=strtok(mon," ");
ch=strtok(NULL,",");
ch1=strtok(ch," ");
if((strcmp(ch1,argv[1]))==0)
{
printf("%s \t\t %s",ep->d_name,ctime(&sb.st_ctime));
}
}
(void)closedir(dp);
}
return 0;
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How do I set bash as default shell mac?
Write a command sequence to find all the files modified in less than 2 days and print the record count of each.
What is awk in shell script?
What is the first line of a shell script called?
What is path in shell script?
How do I open the shell in cmd?
How can we find the process name from its process id?
What are the different variables present in linux shell?
What is bash used for?
What are the default permissions of a file when it is created?
What does $@ mean in shell?
What is a program shell?
How to use arguments in a script?
What are zombie processes?
How do I debug a shell script?