논리적오류
놓아주세요
# include stdio.h
# include stdlib.h
# include string.h
typedef struct{
char name[30];
int caps;
}player; //구조체 선언
int binarysearch(file *f, const char *name, player *p); // 이진 검색을 위한
void copy();
void main()
{
file *f;
player *list;
char n[30];
int i;
int bs;
fopen_s(&f,de.bin, wb);
if(f==null)
{
if(f==null) printf(f 파일 열기 실패\n);
exit(1);
}
list = (player*)malloc(sizeof(player)*10);
if(list == null)
{
printf(할당 실패\n);
exit(1);
} //할당 여부
printf(10명의 선수 정보를 입력하세요\n);
for(i=0; i10; i++)
{
printf(%d번째\n,i+1);
printf(선수 이름 입력하세요 (영문) : );
scanf_s(%s,&list[i].name,sizeof(list));
printf(선수 출전 횟수를 입력하세요 : );
scanf_s(%d,&list[i].caps,sizeof(list));
printf(\n);
} //입력 받는 함수, 선수 정보와, 출전 횟수
fwrite(&list,sizeof(player),10,f);
fclose(f);
copy();
for(i=0; i10; i++)
{
printf(%s %d\n,(list+i)-name,(list+i)-caps);
}
printf(\n선수 이름을 입력하면 출전 횟수가 출력됨\n);
while(1)
{
printf(\n선수 이름을 입력하세요\n);
scanf_s(%s,n, sizeof(n));
if(strcmp(n,done)==0)
{
printf(종료합니다.);
exit(1);
}
bs= binarysearch(f, n, list);
if(bs==1)
{
printf(이름 : %s 횟수: %d, list-name,list-caps);
}
else printf(선수명 오류\n);
}
free(list);
}
void copy()
{
file *ifile, *ofile;
int next;
fopen_s(&ifile,dest.bin, rb);
fopen_s(&ofile, ok.bin, wb);
if(ifile==null||ofile==null){
if(ifile!=null) fclose(ifile);
if(ofile!=null) fclose(ifile);
exit(exit_failure);
}
next = fgetc(ifile);
while(!feof(ifile)){
fputc(next, ofile);
next = fgetc(ifile);
} // while (파일 끝까지)
fclose(ifile);
fclose(ofile);
}
int binarysearch(file *f, const char *name, player *p)
{
int first =0, mid=0, last = 9, comp =0 ;
while(first=last)
{
mid = (first + last) / 2;
fseek(f,sizeof(player)*mid,seek_set);
fread(p,sizeof(player),1,f);
comp= strcmp(p-name,name);
if(comp==0) return 1;
else if(comp 0)
{
last = mid - 1;
}
else
{
first = mid +1;
}
}//while
fclose(f);
return 0;
}
// 실행오류는 없는데요, 검색이 첫번째꺼밖에 안되네요 ! ㅜㅜ
-
너의길
자유게시판에서 C언어 Q&A 게시판으로 이동시켰습니다.
-
뿡뿡
그리고..이진파일로 열은거 같은데요 ㅠㅠ
-
매디
고쳣는데요.. ! 검색부분이 안되는데..ㅜ이유가 뭘까요 ?
-
동은
text 파일은 rb나 wb 모드로 열면 안 되고, rt나 wt로 열어야 됩니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |