Rabu, 04 April 2012
TAS ASD
Tag
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct tnode{
char nama[25];
char alamat[40];
char notelp[10];
char email[20];
struct tnode *next;
};
void addData(tnode **node,char nama[25],char alamat[40],char notelp[10], char email[20]){
tnode *newnode;
newnode=(tnode*)malloc(sizeof(tnode));
strcpy(newnode->nama,nama);
strcpy(newnode->alamat,alamat);
strcpy(newnode->notelp,notelp);
strcpy(newnode->email,email);
newnode->next=*node;
*node=newnode;
}
void main(){
tnode *head=NULL,*curr=NULL,*node=NULL,*simpan=NULL;
int input=0,a,b,i,bantu=0;
char nama1[25];
char nama2[25];
char alamat1[40];
char notelp1[10];
char email1[20];
while(input!=6){
clrscr();
printf("\t\t\tBUKU TELEPON\n\n");
printf("1.) Tambah Data\n");
printf("2.) Hapus Data\n");
printf("3.) Cari Data\n");
printf("4.) Tampil Data\n");
printf("5.) Exit\n\n");
printf("Pilihan anda : ");scanf("%d",&input);
switch(input){
case 1:
clrscr();
printf("Tambah Data\n\n");
printf("Banyak data : ");scanf("%d",&b);
printf("\n");
for (i=1; i<=b; i++){
node=(struct tnode*)malloc(sizeof(struct tnode));
printf("Data ke-%d\n",i);
printf("Nama\t: ");fflush(stdin);gets(nama1);
printf("Alamat\t: ");fflush(stdin);gets(alamat1);
printf("No.Telp\t: ");fflush(stdin);gets(notelp1);
printf("Email\t: ");fflush(stdin);gets(email1);
printf("\n");
addData(&node,nama1,alamat1,notelp1,email1);
if(head==NULL){
head=node;
curr=node;
}
else{
curr->next=node;
curr=node;
}
}
printf("Tekan Sembarang Tombol untuk Kembali ke Menu...");
getch();
break;
case 2:
clrscr();
printf("Hapus Data\n\n");
printf("\"nama\" dari data yang akan dihapus : ");fflush(stdin);gets(nama2);
simpan=head;
head=NULL;node=NULL;curr=NULL;
while(simpan!=NULL){
if(strcmp(simpan->nama,nama2)!=0){
addData(&node,simpan->nama,simpan->alamat,simpan->notelp,simpan->email);
if(head==NULL){
head=node;
curr=node;
}
else{
curr->next=node;
curr=node;
}
}
simpan=simpan->next;
}
printf("\n\n<data dengan nama \"%s\" telah dihapus>\n",nama2);
printf("Tekan Sembarang Tombol untuk Kembali ke Menu...");
getch();
break;
case 3:
clrscr();
bantu=0;
a=1;
printf("Cari Data\n\n");
printf("\"nama\" dari data yang akan dicari : ");fflush(stdin);gets(nama2);
printf("\n");
if(curr!=NULL){
curr->next=NULL;
}
curr=head;
while (curr!=NULL){
if(strcmp(curr->nama,nama2)==0){
printf("Data ke-%d\n",a);
printf("Nama\t: %s\n",curr->nama);
printf("Alamat\t: %s\n",curr->alamat);
printf("No.Telp\t: %s\n",curr->notelp);
printf("Email\t: %s\n\n",curr->email);
bantu++;
}
curr=curr->next;
a++;
}
if(bantu==0)printf("\n\nData tidak ditemukan\n\n");
curr=node;
printf("Tekan Sembarang Tombol untuk Kembali ke Menu...");
getch();
break;
case 4:
clrscr();
a=1;
printf("Tampil Data\n\n");
if(curr!=NULL){
curr->next=NULL;
}
curr=head;
while (curr!=NULL){
printf("Data ke-%d\n",a);
printf("Nama\t: %s\n",curr->nama);
printf("Alamat\t: %s\n",curr->alamat);
printf("No.Telp\t: %s\n",curr->notelp);
printf("Email\t: %s\n\n",curr->email);
curr=curr->next;
a++;
}
curr=node;
printf("Tekan Sembarang Tombol untuk Kembali ke Menu...");
getch();
break;
case 5:
_exit(0);
}
}
}
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar