소스 수정 부탁드립니다. 전화번호부 검색하는거에요..알고리즘 적용
늘다
소스수정 부탁드립니다. 전화번호 검색인데 바이너리, 시퀀셜, 해시검색 알고리즘을 사용하는것이고요.....
구조체 배열로 자료입력받은후에 텍스트 파일 형식으로 쓸겁니다.....
주석은 제 컴퓨터의 VC++이 한글이 깨져버려서 영어로 달았구요......
암튼, 이름으로만 검색합니다. 자료는 이름, 번호, 성별, 나이 순서로 받게 되어잇고요..
각 검색 알고리즘에서 이름을 입력받을 배열을 만들어서 구조체에 입력받은 내용들과 비교해서 검색법에 의해 검색후 출력을 하죠;
근데 해시알고리즘은 제가 잘 몰라서 -_-;; 첨부된 파일에 주석처리 시켜버렸습니다...다른 분꺼 갖구온거라서요 이 소스에 맞게
수정을 해봐야할거같아요;
도움 부탁바래요...........책한권 갖구 나름대로 노력해봤는데 잘 안되네요 ㅠㅠ; 급해요~
실험실 세미나 해야하는데 , 레포트는 아니랍니다..제가 맡은 부분인데 흑~~----------------------------------------- 소스 -------------------------------------------
#include stdio.h
#include string.h
#include stdlib.h
#include conio.h
#define MAX 100
void pList();// view phone list
void input();// insert data
void search();// delete data
void binSearch();// binary search
void seqSearch();// sequential search
//void hash();// hash search
struct subinfo {
char sex[10];
int age;
};
struct phone{
char name[10];
char phoneNo[30];
struct subinfo sub;
} data[MAX];
int choice, fSize, loc=0;
char seek[30];
FILE *fp;
void main(){
if((fp=fopen(phonelist.txt,r+))==NULL)// open textfile to input/output
fp=fopen(phonelist.txt,w+);// make textfile to input/out when no files exist
if(fread(&fSize, sizeof fSize, 1, fp) != 1) {
}
while(1){
fseek(fp, 0L, SEEK_SET);
printf(┌메인메뉴───────────┐\n);
printf(│1. 목록보기 │\n);
printf(│2. 번호추가 │\n);
printf(│3. 번호검색 │\n);
printf(│4. 종 료 │\n);
printf(└───────────────┘\n);
do{
printf((1-4) : );
fflush(stdin); // clear buffer
scanf(%d, &choice);
}while((choice1)||(choice5));
if(choice==1)
pList();
else if(choice==2)
input();
else if(choice==3)
search();
else if(choice==4)
break;
}
fclose(fp);
getche();
}
void pList()
{
while((choice=fgetc(fp))!=EOF) // EOF error check
putchar(choice);
}
void input()
{ // data insert
int i;
for(i=0;i100;i++) {
printf(이름 : );
fflush(stdin);
scanf(%s, data[i].name); // insert name where structure
printf(전화번호 : );
fflush(stdin);
scanf(%s, data[i].phoneNo);
printf(성별 (남M/여F): );
fflush(stdin);
scanf(%s, data[i].sub.sex);
printf(나이 : );
fflush(stdin);
scanf(%d, &data[i].sub.age);
if((fseek(fp, -34L, SEEK_CUR))==0)
fscanf(fp,%3d, &choice);
else
choice=0;
fseek(fp, 0L, SEEK_END);
fprintf(fp,%3d : %10s %15s %c %d\n, choice+1, data[i].name, data[i].phoneNo, data[i].sub.sex, data[i].sub.age);
choice++;
}
}
void search()
{
printf(┌번호수정───────────┐\n);
printf(│1. Sequential Search&; │\n);
printf(│2. Binary Search │\n);
printf(│3. Hash Search │\n);
printf(│4. 종 료 │\n);
printf(└───────────────┘\n);
do{
printf((1-4) : );
fflush(stdin); // clear buffer
scanf(%d, &choice);
if(choice==1)
binSearch();
else if(choice==2)
input();
else if(choice==3)
search();
else if(choice==4)
break;
}while((choice1)||(choice5));
}
void seqSearch()
{
int seeker, found;
fflush(stdin);
printf(이름 : );
gets(data[loc].name);
found = 0;
for(seeker=0;seekerfSize;seeker++)
if(!strcmp(seek, data[seeker].name)) {
printf(이름 : %s 번호 : %s 성별 : %c 나이 : %d\n,data[loc].name, data[loc].phoneNo, data[loc].sub.sex, data[loc].sub.age);
found = 1;
printf(\n);
}
if(!found) printf(전화번호부에 없습니다.);
}
void binSearch()
{
char name[20];
int first, last, mid;
fflush(stdin);
printf(이름 : );
scanf(%s, &name);
first = 0;
last = strlen(name);
printf(%d, last);
while(first = last) {
mid = (first + last)/2;
if(strcmp(name,name[mid])0)
first = mid + 1;
else if(strcmp(name, name[mid])0)
last = mid - 1;
else
break;
}
if(!strcmp(name,name[mid])) {
printf(이름 : %s 번호 : %s 성별 : %c 나이 : %d\n,data[loc].name, data[loc].phoneNo, data[loc].sub.sex, data[loc].sub.age);
}
else printf(목록에 없습니다.);
}
void hash()
{
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2696504 | 플래시 위에 div 올리기 (5) | 큰꽃늘 | 2025-05-30 |
2696458 | 제가 만든 소스 한번 봐주시고 수정 할 꺼 있으면 말해주세요. (실행은 되지만 깜빡거리네요) | 이플 | 2025-05-29 |
2696434 | 퍼센트 레이아웃 질문인데요.. | 나츠 | 2025-05-29 |
2696372 | %=open_main%, %=open_sub% 가 뭘까요? (9) | 행복녀 | 2025-05-29 |
2696347 | 콘솔 프로그램 질문 | 상큼한캔디 | 2025-05-28 |
2696320 | c언어 scanf 함수를 이요해 문자열 입력 받을 시 질문 있습니다. | 슬아라 | 2025-05-28 |
2696292 | 익스플로러9이상에서만 이상한 보더가 보이는데 삭제할수 있나요? | 망고 | 2025-05-28 |
2696263 | 프로그래밍 공부시작 질문 (6) | 진이 | 2025-05-28 |
2696206 | SK2의 플래시를 밴치마킹하려고하는데요.. (1) | 비내리던날 | 2025-05-27 |
2696179 | ie7에서 사라지지가 않네요. (2) | 빛길 | 2025-05-27 |
2696150 | div에 스크롤 생기게 하려면... (2) | 에드가 | 2025-05-27 |
2696123 | 자료구조론 공부중인데 | 김자영 | 2025-05-26 |
2696094 | exe 파일 | 제철 | 2025-05-26 |
2696043 | 제이쿼리 .scroll() 관련 질문드립니다 | 이거이름임 | 2025-05-26 |
2695984 | 마크업상으로 하단에 있으나 우선적으로 이미지파일을 다운로드받는 방법 (1) | 들꿈 | 2025-05-25 |
2695934 | tr 속성값 (9) | 새 | 2025-05-25 |
2695905 | ASP로 개발됐을 때 css가 달라져요 ㅠㅠ (4) | 슬아라 | 2025-05-24 |
2695878 | form을 이용한 다른 페이지로 넘기는 방법을 알려주세요 (1) | 핫파랑 | 2025-05-24 |
2695844 | 저기 암호화 및 복호화 프로그램.. 만들어볼려는대 (2) | 한빛 | 2025-05-24 |
2695814 | [질문] PDA에서 애플릿이 가능한가요? (1) | 봄시내 | 2025-05-24 |