Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
I seem to be lost again, I made a program to try and get more comfortable with hash tables before I attempt 'speller' at this point it compiles but when I run it I get an instant segmentation fault, any hints at what I am missing would be appreciated.
Post Flair (click to view more posts with a particular flair)
Post Body

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

typedef struct node
{
    char word[20];
    struct node *next;
}
node;

int hashs(char *str);
void free_hash(node *kill);
void print_list(node *say);

int main(void)
{
    node *table[26];
    char name[20];
    int place;
    for (int i = 0; i < 26; i  )
    {
        table[i]->next = NULL;
    }

    while (1)
    {
        printf("('e' to exit) enter name: ");
        scanf("s", name);
        if (name[0] == 'e' && name[1] == '\0')
        {
            break;
        }
        place = hashs(name);

        node *n = malloc(sizeof(node));
        if (n == NULL)
        {
            for (int i = 0; i < 26; i  )
            {
                free_hash(table[i]);
            }
            printf("memory issue\n");
            return 89;
        }
        strcpy(n->word, name);
        n->next = table[place]->next;
        table[place]->next = n;


    }

    for (int i = 0; i < 26; i  )
    {
        print_list(table[i]);
    }
    for (int i = 0; i < 26; i  )
    {
        free_hash(table[i]);
    }
}

int hashs(char *str)
{
    return toupper(str[0]) - 'A';
}

void free_hash(node *kill)
{
    if (kill == NULL)
    {
        return;
    }
    free_hash(kill->next);
    free(kill);
}

void print_list(node *say)
{


    for (node *temp = say; temp != NULL; temp = temp->next)
    {
        printf("%s\n", temp->word);
    }

    return;
}

Author
Account Strength
60%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,011
Link Karma
98
Comment Karma
849
Profile updated: 4 days ago
Posts updated: 3 weeks ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago