학교과젠데 해쉬이용하는 거거든??? 아마 파일입출력부분에서 뭔가가 잘못된거같은데 도저히모르겠네ㅠㅠㅠ
해결책좀알려주라 ㅠㅠㅠㅠㅠㅠ
자비로운 컴프갤능력자형들 만세
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define TABLESIZE 137 //테이블사이즈
typedef unsigned int Index;
typedef Index Position;
enum KindOfEntry { Legitimate, Empty };
struct HashEntry
{
char* Element;
enum KindOfEntry Info;
int w;
int l;
float wr;
};
typedef struct HashEntry Cell;
struct HashTbl
{
int TableSize;
Cell *TheCells;
};
typedef struct HashTbl * HashTable;
HashTable InitializeTable(int TableSize);
Position Find(char Key[], HashTable H);
Position Hash(char Key[], int TableSize);
void insert(char Key[], HashTable H,int wt,int lt,int wrt);
int AboutTeam(char name, HashTable H);
int main()
{
char name[15];
FILE *fp;
char n[15];
int wt, lt, wrt;
fp=fopen("Data.txt","r");
HashTable Ha = InitializeTable(TABLESIZE);//137사이즈 생성
for(int p=0;p<38;p++)
{
fscanf(fp," %s",&n);
fscanf(fp," %d",&wt);
fscanf(fp," %d",<);
fscanf(fp," %d",&wrt);
insert(n,Ha,wt,lt,wrt);
}
fclose(fp);
printf("야구팀의 이름을 입력해 주십시오 > ");
scanf("%s",name);//gets(name);
AboutTeam(name[15],Ha);
return 0;
}
HashTable InitializeTable(int TableSize)
{
HashTable H;
int i;
if(TableSize < 0)//1차검사
{
printf("Table size must be over 0");
return 0;
}
H = (HashTbl*)malloc(sizeof(struct HashTbl));
if(H==NULL)//2차검사
{
printf("Out of space");
return 0;
}
H -> TableSize = TABLESIZE;
H ->TheCells = (HashEntry*)malloc(sizeof(Cell)* H->TableSize);
if( H ->TheCells ==NULL)//3차검사
{
printf("Out Of Space");
return 0;
}
for(i=0;i< H->TableSize;i++)//초기화
H->TheCells[i].Info = Empty;
return H;
}
Position Find(char Key[], HashTable H)
{
Position CurrentPos;
int CollisionNum;
CollisionNum=0;
CurrentPos = Hash(Key,H->TableSize);
while(H->TheCells[CurrentPos].Info != Empty && !(strcmp( H->TheCells[CurrentPos].Element, Key)))//strcmp
{
CurrentPos+=(2 * ++CollisionNum) - 1;//quadratic probing
if(CurrentPos >= H->TableSize)
CurrentPos -= H-> TableSize;
}
return CurrentPos;
}
Position Hash(char Key[], int TableSize)
{
Position KEYY;
for(int i=0;Key[i]!=NULL;i++)
KEYY+=Key[i];
return KEYY%TableSize;
}
void insert(char Key[], HashTable H,int wt,int lt,int wrt)
{
Position Pos;
Pos=Find(Key,H);
if(H->TheCells[Pos].Info = Empty)
{
H->TheCells[Pos].Info = Legitimate;
strcpy(H->TheCells[Pos].Element,Key);
H->TheCells[Pos].w = wt;
H->TheCells[Pos].l = lt;
H->TheCells[Pos].wr = wrt;
}
}
int AboutTeam(char name[],HashTable H)
{
Position t = Find(name,H);
if(strcmp( H->TheCells[t].Element, name))
{
printf("%s 는 이번시즌에서 %d 승 %d패를 기록하였으며 승률은 %d 입니다",H->TheCells[t].Element,H->TheCells[t].w,H->TheCells[t].l,H->TheCells[t].wr);
return 0;
}
if(H->TheCells[t].Info = Empty)
{
printf("잘못된 이름을 입력하셨습니다.");
return 0;
}
}
겟아웃 [핡]
자살ㅊㅊ
왜그래형들 ㅜㅠ 뭐가잘못된거야