hi, i'm supposed to create a very simple address program in C & not in C++. my program works but my problem is how to "search & edit a record" and how to "search & delete a record", that is what i lack. this program is really giving me a headache. im also confused on how to use the "strcmp" or "stricmp".
i hope someone can help me. thnx!
this is what i've done so far:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
struct person
{
char fname[20];
char lname[15];
char address[50];
char telephone[10];
};
char Selection(char choice)
{
printf("a. Data Entry");
printf("\nb. Search and Edit a Record");
printf("\nc. Search and Delete a Record");
printf("\nd. Display all Records");
printf("\ne. Exit from the program");
printf("\n\nEnter your choice: ");
scanf(" %c",&choice);
return choice;
}
int Data_Entry (struct person prson[20])
{
char fn[20], ln[15], addy[30], tphone[10];
int i;
printf("Enter info for student no. %d",i+1); gets("\n");
printf("\nFirst Name: "); gets(fn);
strcpy(prson[i].fname, fn);
printf("Last Name: "); gets(ln);
strcpy(prson[i].lname, ln);
printf("Address: "); gets(addy);
strcpy(prson[i].address, addy);
printf("Telephone No.: "); gets(tphone);
strcpy(prson[i].telephone, tphone);
i++;
return i;
}
Display(struct person prson[20], int i)
{
int j, y=3;
clrscr();
printf("Name Address Tel. No.");
for (j=0;j<i;j++ )
{
gotoxy(1,y);printf("%s, %s",prson[j].lname, prson[j].fname);
gotoxy(30,y);printf("%s",prson[j].address);
gotoxy(60,y);printf("%s",prson[j].telephone);
y++;
}
getch();
}
typedef struct person prson;
main()
{
int i=0;
struct person prson[20];
char choice='';
do
{
clrscr();
choice=Selection(choice);
if ( choice=='a' ) {
clrscr();
i=Data_Entry(prson); }
if ( choice=='d' )
Display(prson, i);
} while ( choice!='e' );
printf("\n\n\n Good Bye!");
getch();
}