/*copy Right @ shyam reghu and shyamtr.blogspot.in */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i=0,j=0;
char dp[100];
struct dir
{
char dname[100];
char fname[100][100];
int fcnt;
}dir;
void create()
{
char dp[100];
printf("Enter the file name :\t");
scanf("%s",dp);
printf("sss");
for(i=0;i<dir.fcnt;i++)
{
printf("sss");
if(strcmp(dp, dir.fname[i])==0)
{
printf("File %s already exist please enter another name\n\n\n ", dp);break;
}
}
if(i==dir.fcnt)
{
strcpy(dir.fname[dir.fcnt],dp);
printf("\n\nfile added to the directory successfully...\n\n\n");
}
dir.fcnt++;
}
void delete()
{ char dp[100];
printf("\n Enter the name of the file to delete:\t");
scanf("%s",dp);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(dp, dir.fname[i])==0)
{
printf("File %s is deleted \n",dp);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);break;
}
}
if(i==dir.fcnt)
{
printf("File %s not found\n\n",dp);
}
else
{
dir.fcnt--;
}
}
void search()
{
char dp[100];
printf("\n Enter the name of the file :\t");
scanf("%s",dp);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(dp, dir.fname[i])==0)
{
printf("File %s is found ", dp);break;
}
}
if(i==dir.fcnt)
{
printf("File %s not found",dp);
}
}
void display()
{
if(dir.fcnt==0)
printf("\n Directory Empty");
else
{
printf("\n List of files in the file directory is :\n\t");
for(i=0;i<dir.fcnt;i++)
printf("\t%s\n\t",dir.fname[i]);
printf("\n");
}
}
void main()
{
int ch,i=0;
printf("\nEnter name of directory :\t ");
scanf("%s", dir.dname);
dir.fcnt=0;
while(1)
{
printf("\n\t Enter your choice\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
printf("\t\t* 1. Create File *\n");
printf("\t\t* 2. Delete File *\n");
printf("\t\t* 3. Search File *\n");
printf("\t\t* 4. Display File *\n");
printf("\t\t* 5. Exit *\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
create(); break;
case 2:
delete(); break;
case 3:
search(); break;
case 4:
display(); break;
case 5:
exit(0);
default :
printf(" Wrong entry...please try again\n");
}
}
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i=0,j=0;
char dp[100];
struct dir
{
char dname[100];
char fname[100][100];
int fcnt;
}dir;
void create()
{
char dp[100];
printf("Enter the file name :\t");
scanf("%s",dp);
printf("sss");
for(i=0;i<dir.fcnt;i++)
{
printf("sss");
if(strcmp(dp, dir.fname[i])==0)
{
printf("File %s already exist please enter another name\n\n\n ", dp);break;
}
}
if(i==dir.fcnt)
{
strcpy(dir.fname[dir.fcnt],dp);
printf("\n\nfile added to the directory successfully...\n\n\n");
}
dir.fcnt++;
}
void delete()
{ char dp[100];
printf("\n Enter the name of the file to delete:\t");
scanf("%s",dp);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(dp, dir.fname[i])==0)
{
printf("File %s is deleted \n",dp);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);break;
}
}
if(i==dir.fcnt)
{
printf("File %s not found\n\n",dp);
}
else
{
dir.fcnt--;
}
}
void search()
{
char dp[100];
printf("\n Enter the name of the file :\t");
scanf("%s",dp);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(dp, dir.fname[i])==0)
{
printf("File %s is found ", dp);break;
}
}
if(i==dir.fcnt)
{
printf("File %s not found",dp);
}
}
void display()
{
if(dir.fcnt==0)
printf("\n Directory Empty");
else
{
printf("\n List of files in the file directory is :\n\t");
for(i=0;i<dir.fcnt;i++)
printf("\t%s\n\t",dir.fname[i]);
printf("\n");
}
}
void main()
{
int ch,i=0;
printf("\nEnter name of directory :\t ");
scanf("%s", dir.dname);
dir.fcnt=0;
while(1)
{
printf("\n\t Enter your choice\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
printf("\t\t* 1. Create File *\n");
printf("\t\t* 2. Delete File *\n");
printf("\t\t* 3. Search File *\n");
printf("\t\t* 4. Display File *\n");
printf("\t\t* 5. Exit *\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
create(); break;
case 2:
delete(); break;
case 3:
search(); break;
case 4:
display(); break;
case 5:
exit(0);
default :
printf(" Wrong entry...please try again\n");
}
}
}