Working code! Thanks for help again ItcBitc
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXSIZE 10000
struct hash_list {
char string[15];
int val;
struct hash_list *next;
};
typedef struct hash_list list;
int main(int argc, char *argv[])
{
int hash_function_one(char *s, int T);
list *curr[MAXSIZE], *head, *temphead;
FILE *finp, *fout;
int char_int;
int size;
int hash;
int i;
char string[15];
char *infile;
char *outfile;
infile = argv[1];
outfile = argv[2];
finp = fopen(infile, "r");
fout = fopen(outfile, "w");
head = NULL;
fscanf(finp, "%d", &size);
while((fscanf(finp, "%s", string))!= EOF)
{
i = hash_function_one (string, size);
if(curr[i]->string == NULL)
{
curr[i] = (list*)malloc(sizeof(list));
strcpy(curr[i]->string, string);
head = curr[i];
head->next = NULL;
}
else
{
head = curr[i]; //<- had to add this
curr[i] = (list*)malloc(sizeof(list));
strcpy(curr[i]->string, string);
curr[i]->next = head;
// head = curr[i]; <- and get rid of this
}
}
for(i=0; i<17;i++)
{
printf("\n");
while(curr[i])
{
printf("%s ", curr[i]);
curr[i] = curr[i]->next;
}
}
}
int hash_function_one (char *s, int T)
{
int h = 0, a = 127, temp;
for (; *s != 0; s++)
{
temp = (a * h + *s);
if (temp < 0)
temp = -temp;
h = temp % T;
}
return h;
}