|
 |
search มันเพี้ยนๆ ไม่รู้เกิดจากตรงไหน รบกวนหน่อยครับ |
|
 |
|
|
 |
 |
|
ติดปัญหาส่วนของการ search ครับ รบกวนช่วยดูหน่อยครับผมCode (C#)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct profile{
char lecturer_id[8];
char major_id[3];
char faculit_id[3];
char name[10];
char surname[20];
char item_teaching[30];
char room_lecturer[10];
char email[20];
} pro;
void insert_data();
void delete_data();
void search_data();
main(){
int choice;
char temp[]={0};
do{
clrscr();
printf("##############################\n");
printf("#____ Profile Lecturer _____#\n");
printf("##############################\n");
printf("# Please select choice #\n");
printf("# 1. Insert Data #\n");
printf("# 2. Delete Data #\n");
printf("# 3. Search Lecturer Data #\n");
printf("# 4. Exit #\n");
printf("##############################\n");
printf("Please select choice (1-4 only):");
gets(temp);
choice = atoi(temp);
if(choice==1) insert_data();
else if(choice==2) delete_data();
else if(choice==3) search_data();
}while (choice!=4);
}
void insert_data(){
FILE *fp;
char ans;
char temp[]={0};
if((fp=fopen("profile.txt","ab"))==NULL){
printf("Cannot open file for insert data\n");
getch();
exit(1);
}
do{
printf("\n\n Please insert profile data \n");
printf("Lecturer ID :");gets(pro.lecturer_id);
printf("Major ID :");gets(pro.major_id);
printf("Faculit ID :");gets(pro.faculit_id);
printf("Name :");gets(pro.name);
printf("Surname :");gets(pro.surname);
printf("Item_Teaching :");gets(pro.item_teaching);
printf("Room Lecturer :");gets(pro.room_lecturer);
printf("Email :");gets(pro.email);
//fwrite(&pro.sizeof(pro),1,fp);
if(ferror(fp)){
printf("Error for insert data\n");
getch();
exit(1);
}
printf("Continue(press C) or Exit(prsee E) :");
ans = getche();
}
while(ans !='E');
fclose(fp);
}
void delate_data(){
FILE *fp;
int i=0;
char ans;
char rec[5];
if((fp=fopen("profile.txt","rb+"))==NULL){
printf("Cannot open file for delete data \n");
getch();
exit(1);
}
printf("\n\nThis is profile for dalete\n");
do{
while (1){
fread(&pro,sizeof(pro),1,fp);
if(ferror(fp)){
printf("Error to read data for delete\n");
getch();
exit(1);
}
if(feof(fp))
break;
++i;
printf("%d .%s \t\t",i,pro.lecturer_id);
}
printf("\n Do you want to delete data (Y or N) :");
ans=getche();
if(ans=='Y'){
printf("\n Enter record number :");
gets(rec);
fseek(fp,((atoi(rec)-1)*sizeof(pro)),SEEK_SET);
// strcpy(pro.lecturer_id,"\0");
fwrite(&pro,sizeof(pro),1,fp);
if(ferror(fp)){
printf("Error for dalete data\n");
getch();
exit(1);
}
printf("Delete data complete\n");
}
printf("\nContinue (press C) or Exit (press E) :");
ans=getche();
printf("\n");
}
while (ans!='E');
fclose(fp);
}// dalete
void search_data(){
FILE *fp;
char ans;
char id[5];
if ((fp=fopen("profile.txt","rb"))==NULL){
printf("Cannot open file search data\n");
getch();
exit(1);
}
do{
printf("\n\nPlease enter profile id for search :");
scanf("%s",id);
while (1){
fread(&pro,sizeof(pro),1,fp);
if(ferror(fp)){
printf("Error for search data\n");
getch();
exit(1);
}
if (ferror(fp)) break;
//if(strcmp(id,pro.lecturer_id)==0){
printf("Data Found !!!\n");
printf("Lecturer ID :");gets(pro.lecturer_id);
printf("Major ID :");gets(pro.major_id);
printf("Faculit ID :");gets(pro.faculit_id);
printf("Name :");gets(pro.name);
printf("Surname :");gets(pro.surname);
printf("Item_Teaching :");gets(pro.item_teaching);
printf("Room Lecturer :");gets(pro.room_lecturer);
printf("Email :");gets(pro.email);
break;
}
}
if(strcmp(id,pro.lecturer_id)!=0)
printf("No profile in lecturer ID %s \n\n",id);
printf("Continue (press C) or Exit (press E) :");
rewind(fp);
ans= getche();
printf("\n");
}
while (ans!='E');
fclose(fp);
}
Tag : C#
|
|
 |
 |
 |
 |
Date :
2012-03-29 15:27:02 |
By :
ภาคภูมิ |
View :
1107 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้เรียบร้อยแล้วครับ พอดีเอ๋อไปนิดหน่อย อิอิ
|
 |
 |
 |
 |
Date :
2012-03-29 16:19:01 |
By :
ภาคภูมิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|