Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/********************************************************************************/
#define defal "Adrees.txt"
#define setting "Setting.txt"
#define Addres "Address:"
#define first_name "First_Name:"
#define last_name "Last_name:"
#define middel_name "Middel Name:"
#define nick_name "Nick Name:"
#define phone_number "Phone Number:"
#define New "\n"
#define line "=========================================================="
#define html "Adress.html"
/**********************************************************************************/
main()
{
int ch;
FILE *file,*htt,*fg,*cp;
struct con
{
char first_namel[40];
char last_namel[40];
char middel_namel[40];
char nick_namel[40];
char phone_numberl[20];
char addressl[20];
}data;
char read[50],read2[50],newname[80];
char ADDRESS[80],cplist[80],buffer[80];
printf("=====================================\n");
printf("Welcome To koofar's maka Addres Book\n");
printf("By Storm MaN \"Gr8ts To Linuxer AS strikerX ,sAFA7_eLNet,Ray,Hacko,Security Gurus All,Linuxac jsut the good people\n\"");
printf("Chosse Between The Given List\n");
printf("================================\n");
printf("Loding setting");
fg=fopen(setting,"ab");
fclose(fg);
fg=fopen(setting,"rb");
fscanf(fg,"%s",ADDRESS);
fclose(fg);
printf("\n1>Add Contact\n2>See All Contacts\n3>Delete All Contacts\n4>Dumb to Html\n5>Reanme contact list\n6>copy contact list\n7>Search cnotatct\n8>How Many Conatcs\n10>exit\n:");
fscanf(stdin,"%d",&ch);
switch(ch)
{
case 1:
getchar();
fflush(stdin);
fflush(stdin);
printf("\nAdding Contact");
printf("\nfirst_name:");
gets(data.first_namel);
printf("\nLast_Name:");
gets(data.last_namel);
printf("\nMiddel name:");
gets(data.middel_namel);
printf("\nNick Name:");
gets(data.nick_namel);
printf("\nphone number:");
gets(data.phone_numberl);
printf("\nAddress:");
gets(data.addressl);
fflush(stdin);
file=fopen(ADDRESS,"ab");
if(file != NULL)
{
if(!feof(file))
{
fputs(first_name,file);
fputs(data.first_namel,file);
fputs(New,file);
fputs(last_name,file);
fputs(data.last_namel,file);
fputs(New,file);
fputs(middel_name,file);
fputs(data.middel_namel,file);
fputs(New,file);
fputs(nick_name,file);
fputs(data.nick_namel,file);
fputs(New,file);
fputs(phone_number,file);
fputs(data.phone_numberl,file);
fputs(New,file);
fputs(Addres,file);
fputs(data.addressl,file);
fputs(New,file);
fputs(line,file);
fputs(New,file);
rewind(file);
}
}
fclose(file);
sleep(1500);
printf("\nPress enter To exit.......");
fflush(stdin);
getchar();
fflush(stdin);
break;
case 2:
fflush(stdin);
printf("\nSeeing All Contact:\n");
file=fopen(ADDRESS,"rb");
fflush(stdout);/*cannot use system cls cause we are not dealing with a defined opreting system*/
while(!feof(file))
{
while((fgets(read,50,file))!=NULL)
printf("%s",read);
printf("\n");
}
fclose(file);
fflush(stdin);
fflush(stdout);
printf("\nPress enter To exit.......");
fflush(stdin);
getchar();
fflush(stdin);
sleep(1500);
break;
case 3:
fflush(stdin);
printf("\nBy By contacts");
remove(ADDRESS);
file=fopen(ADDRESS,"wb");
fprintf(file,"no cnotacts");
fclose(file);
sleep(1500);
printf("\nPress enter To exit.......");
fflush(stdin);
getchar();
fflush(stdin);
break;
case 4:
fflush(stdin);
printf("\nMakking it html OK\n");
file=fopen(ADDRESS,"rb");
htt=fopen(html,"ab");
fputs("<html><center>",htt);
while((fgets(read2,50,file))!=NULL)
{
fputs(read2,htt);
fputs("<br>",htt);
}
fputs("</html></center>",htt);
fclose(file);
fclose(htt);
sleep(1500);
printf("\nPress enter To exit.......");
fflush(stdin);
getchar();
fflush(stdin);
break;
case 5:
fflush(stdin);
printf("\nEnter The New Name:");
gets(newname);
if((rename(ADDRESS,newname)) == 0)
{
printf("\nFile hase been renamed to%s",newname);
fg=fopen(setting,"wb");
rewind(fg);
fwrite(newname,sizeof(char),strlen(newname),fg);
fclose(fg);
}
else
{
printf("\nCannot rename file name");
}
break;
case 6:
fflush(stdin);
printf("\nEnter a Path For The New Contact List:");
gets(cplist);
file=fopen(ADDRESS,"rb");
cp=fopen(cplist,"wb");
while((fgets(buffer,80,file))!= NULL)
{
fputs(buffer,cp);
}
if(cp)
{
printf("File IS In %s",cplist);
}
else
{
fprintf(stderr,"Error");
}
break;
case 10:
printf("\nBye Bye");
sleep(1500);
exit(0);
}
return 0;
}
/* there has to be a file named Setting.txt in the Directory the program in*/
Now The Problem is coming
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
FILE *fp;
char se[80];
char buffer[80];
gets(se);
fp=fopen("file.txt","rb");
do
{
fgets(buffer,strlen(se)+1,fp);
printf("\n%s\n%s",buffer,se);
if(strcmp(buffer,se)==0)
{
printf("%sfound\n",buffer);
}
}while(fp!=NULL);
fclose(fp);
}
i will explain it