Hot answers tagged

1

I'm surprised there aren't more problems! Look at the following code: while ((ch = fgetc(d)) != EOF) { fscanf(d, "%s", dictword); The while statement scans the first letter from each line in the input file. Next, the fscanf line scans the rest of the "current" line. In the case of a dictionary where "A" is the ...


1

First, since the global declarations and other code that comes at the top of the file weren't included, I've had to guess at some things to test the code. I suspect that sumstring, used in the hash function, is declared as a global. If so, that's a big problem here. Since it's not initialized inside of the hash function, it is also not reset between calls. ...


1

I'd say crypt works as expected, and is not the cause for your problem. Passing z or z_val does the same thing, as arrays are passed as a pointer to their first element. Same goes for returning o or output. And here's a problem: The array output got declared on to_password's stack. When it returns, that area of the stack will be marked as "unused" (the ...


1

A couple of things, if your if condition returns 1 in case of error you don't need an else clause, this only complicates the code. In addition you should print the correct way to use the program, a simple error message can lead to confusion for the user: printf ("usage: ./crack <string> \ n"); or something similar. By the way to get the hash of the ...


1

You set height equal to four. This also sets j to four. See how this works on the first line: i = 0 by definition, so you print a " " every time j is above i and deduct one from j. You can repeat this four times: j=4, 3, 2 and 1. This is one more than you need. To fix it, you need to change for(int j=height; j>i; j--) for for(int j=height; j>(i+1); ...


1

Try any user with the password password. All users are created with that same password. This hashp = generate_password_hash("password") treats password as a string literal, because of the ". You probably meant the password that was submitted with the form.


1

new->s=""; lets new->s point to an empty string stored in a read-only area. strcpy(new->s,val); then tries to write to that read-only area. You need writable memory associated to the pointer. You could for example declare it as char s[LENGTH+1]; in the struct (LENGTH is declared in dictionary.h and is the length of the longest word to consider).


1

In your load function, you are created a new_node, adding it to your linked list, and then freeing it free(new_node);. You've just thrown away your node. You shouldn't free your nodes until you are finished (in the unload function).


1

The code will return index % HASHSIZE;, but where is index calculated? Maybe index was supposed to be hash? If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)


1

Putting actual code into a .h header file is something that should never be done. Any hash function, or any function for that matter, should be in a .c file. In this case, you should be putting your hash function in the dictionary.c file, mostly because it will need to be there to pass check50. Remember to place the function prototype (or the function ...


1

You're right that it is in the load function. The seg fault occurs near the end. previous -> next = new; The problem occurs when you are adding the first word for a given hash index to the hashtable array. At this point, previous is still set to null. If you try to assign something to previous->next when previous = null, it seg faults. Next, you have ...


Only top voted, non community-wiki answers of a minimum length are eligible