-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexFiles.c
50 lines (47 loc) · 1.17 KB
/
indexFiles.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**************************/
/*Hector Castillo Martinez*/
/*CS 241 */
/**************************/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "hashtable.h"
#include "indexFiles.h"
/* Reads in a file and stores each element in the hashtable.
*Filename to be open passed from graph and need to be in directory.
*done word by word using isalpha to get rid of all not alphabetical
*characers*/
void readInFile(char* fn,struct HTable* table,float pr)
{
struct HashElt* temp;
FILE* file=fopen(fn,"r");
int c;
int index=0;
char* word=malloc(sizeof(char)*20);
if(file==NULL)
{
perror("Error in readInFile");
return;
}
while((c=fgetc(file))!=EOF)
{
if((c>=65 && c<=90) || (c>=97 && c<=122))/*alphabetical char*/
{
c=tolower(c);
word[index]=c;
index++;
}
if(isalpha(c)==0 && word[0]!=0)/*words needs to be built*/
{
temp=createHashElt();
temp->url=fn;
temp->token=word;
temp->pageRank=pr;
insert(temp,table);
index=0;
word=(char*)calloc(20,sizeof(char));
}
}
fclose(file);
}