Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "inc.h"
- #define LENGTH 103
- int main(int argc, char* argv[]) {
- FILE* infile;
- char str[100];
- int index;
- char *table[LENGTH];
- int i = 0, j = 0;
- infile = fopen(argv[1], "r"); // read the file.
- if (infile == NULL) {
- perror("Cannot open the file specified.\n");
- exit(1);
- }
- // process file.
- printf("Data from file: \n");
- while (fgets(str, 100, infile) != NULL) {
- // get the index for the current string.
- index = hash(str, LENGTH);
- printf("Index for %s is %d\n", str, index);
- table[index] = strdup(str);
- }
- fclose(infile); // done with the file.
- // report the string and locations in hash table.
- for (i = 0; table[i][j] != '\0'; ++i) {
- if (table[i]) {
- for (j = 0; table[i][j] != '\0'; ++j)
- printf("%c", table[i][j]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement