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 can I set the default rwx permission to all users on every file which is created in the current shell?
Is shell script a programming language?
What is the default shell of solaris?
How to debug the problems encountered in the shell script/program?
How to check if the previous command was run successfully?
What does egrep mean?
how to get part of string variable with echo command only?
What makes c shell a more preferable option than the bourne shell?
determine the output of the following command: echo ${new:-variable}
Write a command sequence to find all the files modified in less than 2 days and print the record count of each.
What does the sh command do?
What are the default permissions of a file when it is created?
What is path variable bash?
Using set -A write a script to print the output of the ls command in 5 columns with two spaces between each column. Pretend that ls does not have multicolumn output.
Why do we write bin bash in shell scripts?