MasterKin
September 30th, 2002, 16:52
hi need help...
my teach asked me for a program to let me input names kinda record style with the ff options... input, delete, edit, search..
anyway got all working except the edit... can someone pls help me...
thanks..
here is the code i made
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct my_project
{
char name[50],age[5],address[50],
phone[50];
} data[3];
int list_info=0;
int c;
char ch;
void ADD_ENTRY(void);
void SEARCH(void);
void DELETE(void);
void EDIT(void);
void main(void)
{
FILE*fptr;
fptr=fopen("tc.txt","a+");
do
{
clrscr();
gotoxy (25,6);printf("Main Menu");
gotoxy (25,8);printf("[1] Add Entry");
gotoxy (25,9);printf("[2] Edit");
gotoxy (25,10);printf("[3] Search By Name");
gotoxy (25,11);printf("[4] Delete");
gotoxy (25,12);printf("[5] Exit");
gotoxy (18,14);printf("Press The Corresponding # of your choice:");
ch=getch();
switch(ch)
{
case '1': ADD_ENTRY();
getch(); break;
case '2': EDIT();
getch(); break;
case '3': SEARCH();
getch(); break;
case '4': DELETE();
getch(); break;
}
}while (ch!='5');
fscanf(fptr,"%s%s%s%s",data[list_info].name,data[list_info].address,data[list_info].age,data[list_info].phone);
fclose(fptr);
list_info++;
}
void ADD_ENTRY(void)
{
FILE*fptr;
fptr=fopen("tc.txt","a+");
clrscr();
gotoxy (25,5);printf(" Add Your Entry Here");
gotoxy (25,7);printf("Name:");
gets(data[list_info].name);
gotoxy (25,8);printf("Age:");
gets(data[list_info].age);
gotoxy (25,9);printf("Address:");
gets(data[list_info].address);
gotoxy (25,10);printf("Phone:");
gets(data[list_info].phone);
fprintf(fptr,"%s%s%s%s",data[list_info].name,data[list_info].address,data[list_info].age,data[list_info].phone);
list_info++;
fclose(fptr);
}
void SEARCH(void)
{
char find=0,count=0,ngalan[10];
clrscr();
gotoxy (25,7);printf("Searching For Somebody's File?:");
gotoxy (25,9);printf("Enter The Name:");
gets(ngalan);
clrscr();
for (count=0;count<list_info;count++)
{
if (strcmp(ngalan,data[count].name)==0)
{
find=1;
break;
}
}
if (find==1)
{
gotoxy (25,8);printf("Name: %s",data[count].name);
gotoxy (25,9);printf("Age: %s",data[count].age);
gotoxy (25,10);printf("Address: %s",data[count].address);
gotoxy (25,11);printf("Phone: %s",data[count].phone);
}
else
{
gotoxy (25,7);printf("Sorry...");
gotoxy (25,8);printf("File Not Found!");
}
}
void DELETE(void)
{
char find=0,count=0,x,ngalan[10];
clrscr();
gotoxy (5,3);
printf("Delete Entry");
gotoxy (12,5);
printf("Enter the name:");
gets(ngalan);
for (count=0;count<list_info;count++)
{
if (strcmp(ngalan,data[count].name)==0)
{
find=1;
break;
}
}
if (find==1)
{
printf("\nName: %s",data[count].name);
printf("\nAge: %s",data[count].age);
printf("\nAddress: %s",data[count].address);
printf("\nPhone: %s",data[count].phone);
printf("\nPress any key to delete...");
getch();
for (x=count;x<list_info-1;x++)
{
strcpy(data[x].name,data[x+1].name);
strcpy(data[x].age,data[x+1].age);
strcpy(data[x].address,data[x+1].address);
strcpy(data[x].phone,data[x+1].phone);
}
list_info--;
printf("\n\n%s's file has been successfully deleted!",ngalan);
}
else
{
printf("File not found!");
}
}
void EDIT(void)
{
char find=0,count=0,pangan[20];
FILE*fptr;
fptr=fopen("project.txt","a+");
clrscr();
for (count=0;count<list_info;count++)
{
gotoxy (25,8+count);printf("Name: %s",data[count].name);
}
gotoxy (25,15);printf("Type first his/ her name.");
gotoxy (25,16);printf("Enter name: ");
gets(pangan);
for (count=0;count<list_info;count++)
{
if (strcmp(pangan,data[count].name)==0)
{
find=1;
break;
}
}
if (find==1)
{
clrscr();
gotoxy (25,8);printf("Name: %s",data[count].name);
gotoxy (25,9);printf("Age: %s",data[count].age);
gotoxy (25,10);printf("Address: %s",data[count].address);
gotoxy (25,11);printf("Phone: %s",data[count].phone);
gotoxy (25,13);printf("Press any key to edit...");
ch=getch();
gotoxy (31,8);gets(data[count].name);
gotoxy (30,9);gets(data[count].age);
gotoxy (33,10);gets(data[count].address);
gotoxy (32,11);gets(data[count].phone);
gotoxy (25,13);printf("%s's file has been successfully editted...",pangan);
}
else
{
clrscr();
gotoxy (25,7);printf("Sorry...");
gotoxy (25,8);printf("File Not Found!");
}
fscanf(fptr,"%s%s%s%s",data[list_info].name,data[list_info].address,data[list_info].age,data[list_info].phone);
list_info++;
fclose(fptr);
}
my teach asked me for a program to let me input names kinda record style with the ff options... input, delete, edit, search..
anyway got all working except the edit... can someone pls help me...
thanks..
here is the code i made
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct my_project
{
char name[50],age[5],address[50],
phone[50];
} data[3];
int list_info=0;
int c;
char ch;
void ADD_ENTRY(void);
void SEARCH(void);
void DELETE(void);
void EDIT(void);
void main(void)
{
FILE*fptr;
fptr=fopen("tc.txt","a+");
do
{
clrscr();
gotoxy (25,6);printf("Main Menu");
gotoxy (25,8);printf("[1] Add Entry");
gotoxy (25,9);printf("[2] Edit");
gotoxy (25,10);printf("[3] Search By Name");
gotoxy (25,11);printf("[4] Delete");
gotoxy (25,12);printf("[5] Exit");
gotoxy (18,14);printf("Press The Corresponding # of your choice:");
ch=getch();
switch(ch)
{
case '1': ADD_ENTRY();
getch(); break;
case '2': EDIT();
getch(); break;
case '3': SEARCH();
getch(); break;
case '4': DELETE();
getch(); break;
}
}while (ch!='5');
fscanf(fptr,"%s%s%s%s",data[list_info].name,data[list_info].address,data[list_info].age,data[list_info].phone);
fclose(fptr);
list_info++;
}
void ADD_ENTRY(void)
{
FILE*fptr;
fptr=fopen("tc.txt","a+");
clrscr();
gotoxy (25,5);printf(" Add Your Entry Here");
gotoxy (25,7);printf("Name:");
gets(data[list_info].name);
gotoxy (25,8);printf("Age:");
gets(data[list_info].age);
gotoxy (25,9);printf("Address:");
gets(data[list_info].address);
gotoxy (25,10);printf("Phone:");
gets(data[list_info].phone);
fprintf(fptr,"%s%s%s%s",data[list_info].name,data[list_info].address,data[list_info].age,data[list_info].phone);
list_info++;
fclose(fptr);
}
void SEARCH(void)
{
char find=0,count=0,ngalan[10];
clrscr();
gotoxy (25,7);printf("Searching For Somebody's File?:");
gotoxy (25,9);printf("Enter The Name:");
gets(ngalan);
clrscr();
for (count=0;count<list_info;count++)
{
if (strcmp(ngalan,data[count].name)==0)
{
find=1;
break;
}
}
if (find==1)
{
gotoxy (25,8);printf("Name: %s",data[count].name);
gotoxy (25,9);printf("Age: %s",data[count].age);
gotoxy (25,10);printf("Address: %s",data[count].address);
gotoxy (25,11);printf("Phone: %s",data[count].phone);
}
else
{
gotoxy (25,7);printf("Sorry...");
gotoxy (25,8);printf("File Not Found!");
}
}
void DELETE(void)
{
char find=0,count=0,x,ngalan[10];
clrscr();
gotoxy (5,3);
printf("Delete Entry");
gotoxy (12,5);
printf("Enter the name:");
gets(ngalan);
for (count=0;count<list_info;count++)
{
if (strcmp(ngalan,data[count].name)==0)
{
find=1;
break;
}
}
if (find==1)
{
printf("\nName: %s",data[count].name);
printf("\nAge: %s",data[count].age);
printf("\nAddress: %s",data[count].address);
printf("\nPhone: %s",data[count].phone);
printf("\nPress any key to delete...");
getch();
for (x=count;x<list_info-1;x++)
{
strcpy(data[x].name,data[x+1].name);
strcpy(data[x].age,data[x+1].age);
strcpy(data[x].address,data[x+1].address);
strcpy(data[x].phone,data[x+1].phone);
}
list_info--;
printf("\n\n%s's file has been successfully deleted!",ngalan);
}
else
{
printf("File not found!");
}
}
void EDIT(void)
{
char find=0,count=0,pangan[20];
FILE*fptr;
fptr=fopen("project.txt","a+");
clrscr();
for (count=0;count<list_info;count++)
{
gotoxy (25,8+count);printf("Name: %s",data[count].name);
}
gotoxy (25,15);printf("Type first his/ her name.");
gotoxy (25,16);printf("Enter name: ");
gets(pangan);
for (count=0;count<list_info;count++)
{
if (strcmp(pangan,data[count].name)==0)
{
find=1;
break;
}
}
if (find==1)
{
clrscr();
gotoxy (25,8);printf("Name: %s",data[count].name);
gotoxy (25,9);printf("Age: %s",data[count].age);
gotoxy (25,10);printf("Address: %s",data[count].address);
gotoxy (25,11);printf("Phone: %s",data[count].phone);
gotoxy (25,13);printf("Press any key to edit...");
ch=getch();
gotoxy (31,8);gets(data[count].name);
gotoxy (30,9);gets(data[count].age);
gotoxy (33,10);gets(data[count].address);
gotoxy (32,11);gets(data[count].phone);
gotoxy (25,13);printf("%s's file has been successfully editted...",pangan);
}
else
{
clrscr();
gotoxy (25,7);printf("Sorry...");
gotoxy (25,8);printf("File Not Found!");
}
fscanf(fptr,"%s%s%s%s",data[list_info].name,data[list_info].address,data[list_info].age,data[list_info].phone);
list_info++;
fclose(fptr);
}