ดูทีคับ
ผมทำโปรแกรมหอพักอ่าแบบทำการSearchโดยดึงมาจากไฟล์อะคับแต่กลัวส่งอาจารย์ไม่ผ่านอะคับคือทำโปรเจ็คอะผมควรเสริมควรแก้ไขตรงไหนช่วยบอกทีคับคิดไม่ออก
#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h>
struct THONGSUKSAI{ char id[6]; char idcard[14]; char name[20]; char surname[20]; char telphone[20]; char age[5]; char syn[5]; char watercharge[5]; }t;
void insert_data(); void search_data(); void main (){ int key; char t[]={0}; do{ clrscr(); printf(\" ** \\n\"); printf(\" ****** \\n\"); printf(\" ************** \\n\"); printf(\" * Hello * \\n\"); printf(\" ************** \\n\"); printf(\"***************************************\\n\"); printf(\"* Welcome to thongsuksai hotel *\\n\"); printf(\"* Please select key *\\n\"); printf(\"* 1. Search Data *\\n\"); printf(\"* 2. Exit *\\n\"); printf(\"***************************************\\n\"); printf(\"Please select key (1-2 only) :\"); gets(t); key=atoi(t); if (key==1) search_data(); }while(key!=2); }
void search_data(){ FILE*fp; int x; char a; char n[20]; if((fp=fopen(\"THONGSUK.TXT\",\"r\"))==NULL) { printf(\"Cann\'t open file for delete data\\n\"); getch(); exit(1); } do{
printf(\"\\n\\nEnter for search :\"); scanf(\"%s\",n); while(1){ fscanf(fp,\"%s\\t%s\\t%s\\t%s\\t%s\\t%s\\n%s\\n%s\\n\",t.id,t.idcard,t.name,t.surname,t.telphone,t.age,t.syn,t.watercharge);
if(strcmp(n,t.id)==0){ printf(\" Data !!!!\\n\"); printf(\"id :%s\\n\",t.id); printf(\"idcard :%s\\n\",t.idcard); printf(\"name :%s\\n\",t.name); printf(\"surname :%s\\n\",t.surname); printf(\"telphone :%s\\n\",t.telphone); printf(\"age :%s\\n\",t.age); printf(\"syn :%s\\n\",t.syn); printf(\"watercharge :%s\\n\",t.watercharge); break;
}if(feof(fp)) break; } if(strcmp(n,t.id)!=0) printf(\"No THONGSUK id : %s \\n\\n\",n); printf(\"Continue(Key C) or Exit(Key E) : \"); a=getche(); rewind(fp); printf(\"\\n\"); }while(a!=\'E\'); fclose(fp); }
|