Questions tagged [pset5]

The problem set for Week 5 will challenge you to apply what you've learned about pointers, memory management, file i/o and structs, creating more complex data structures (such as Hash Tables or Tries) and leveraging their power to write a lightning-fast spell check algorithm.

Filter by
Sorted by
Tagged with
0
votes
1answer
575 views

pset 05 trie large dictionary unload issue

I am working through pset5 (Mispellings) using a trie and I am stumped. This is the error exactly from gdb (sample is a text file I made and works just fine with the small dictionary): Starting ...
0
votes
2answers
2k views

incompatible pointer types passing in strcpy?

char word[LENGTH+1]; while(fscanf(file,"%s",word)!=EOF) { node* new_node=malloc(sizeof(node)); strcpy(new_node->word,word) } there is error of strcpy() error: incompatible pointer types ...
0
votes
1answer
1k views

Pset5 Speller Load / Check Problem

I have spent hours checking my code but still couldn't figure out which part went wrong. The program executed without throwing errors but the misspelled words identified were wrong. I think the ...
0
votes
1answer
605 views

how do I malloc nodes for use in a trie data structure

How do I use malloc to allocate memory for use in a trie data structure given: typedef struct node { bool in_word; struct node* children[27]; } LETTERNODE; What is the syntax for malloc in ...
0
votes
1answer
190 views

pset5 why only strcpy works

In load, when I assign the word I loaded from dictionary to new_node, I originally used new_node->word = new_word but an error told me that it is non assignable. However, when I use strcpy it ...
0
votes
1answer
606 views

Resize.c not working in some cases

I'm struggling with resize.c for quite some time. I've come to the point where it perfectly resizes sometimes (for example, small.bmp with factor 5) but sometimes it doesnt(for example, small.bmp with ...
0
votes
1answer
139 views

Infinite loop and unable to check for next JPG

My program is stuck in a loop and I can't figure out why. The problem is in the do while loop but logically it should work. The program checks performs fwrite and then freads a new 512 bytes to the ...
0
votes
1answer
194 views

Why is file pointer null on Whodunit and how can I fix?

(gdb) b main Breakpoint 1 at 0x804869e: file whodunit.c, line 18. (gdb) r infile outfile Starting program: /home/jharvard/Dropbox/pset5/bmp/whodunit infile outfile Breakpoint 1, main (argc=3, argv=...
0
votes
2answers
581 views

recover all the images as expected but fails check50 last 3 tests

I recovers all the 50 images and check my program correctness through check50. but it fails last three test can you check my code and tell me where i'm wrong here's the check50 error :) recover.c ...
0
votes
1answer
433 views

resize vertically is not working properly

i take the re-copy approach guys and badly stuck in that problem .. everything my code is fine just writing pixel is wrong somewhere. i'm posting my writing snippet of my resize please give me some ...
0
votes
1answer
571 views

recover returns corrupted images

I'm currently writing recover.c for pset5 last exercise. The program I designed runs ok, outputs the expected amount of JPGs at what I would expect to be reasonable sizes. However the JPGs are broken ...
0
votes
1answer
511 views

“Unsupported file format” error when checking the format of BMP files

pset5 is the first pset so far that I've really struggled to understand. I've written the code, but I can't test the algorithms because everytime I run it I get "Unsupported file format" // ensure ...
0
votes
1answer
651 views

pset5 recover error with jpeg file

I keep getting "error interpreting jpeg image file (Not a jpeg file: starts with 0x00 0xd8)", even though gdb tells me buffer[0] is 0xff. A similar question has been posted on reddit, but I couldn't ...
0
votes
1answer
776 views

Seg Fault in Recover.c

I cannot seem to get to get rid of this seg fault. In my loop I basically have this (semi-pseudo code): fread(in); if(nf == 0xffd8ffe0 || nf == 0xffd8ffe1) { f++; fclose(out); ...
0
votes
1answer
291 views

pset5 resize segmentation fault?

I am getting a segmentation fault when I run this program, and am fairly sure that the problem is in the third for loop, where I try to copy the bytes from *pixel to *line, duplicating each byte '...
0
votes
1answer
525 views

fread reaches eof prematurely (pset 5)

Scratching my head on this one folks. My current program reads the first two chunks of 512 bytes of the first jpg (thats actually 3 reads total as the first 512 chunk is empty), but then fread fails ...
0
votes
2answers
305 views

Why am I not able to write n elements of a specific size correctly?

Given these two blocks of code fwrite(&x, sizeof(y), n, z); And for (int i = 0; i < n; i++) { fwrite(&x, sizeof(y), 1, z); } I was actually working on resize when my resized images ...
0
votes
2answers
375 views

Pset5 resize works but fails check50 TODO- bytes and headers match staff bmp file

I know others have had a similar problem and I have tried to find my error but I see no difference between my bmp file and the staff.bmp. Since reddit seems very quiet these days I am posting here ...
0
votes
2answers
33 views

PSET5 speller segmentation fault

Can anyone help with segmentation fault. I have tried running debug50 and aparently the fault hits at line "if (head -> next != NULL)" in the load function. Aparently "table" is ...
0
votes
1answer
15 views

Why are check50 and valgrind telling different things?

When I run help50 valgrind ./speller texts/lalaland/txt it returns ==1123== ==1123== HEAP SUMMARY: ==1123== in use at exit: 472 bytes in 1 blocks ==1123== total heap usage: 143,096 allocs, 143,...
0
votes
1answer
62 views

Speller not working! What's going on?

My function returns this: WORDS MISSPELLED: 375902 WORDS IN DICTIONARY: 143091 WORDS IN TEXT: 376904 TIME IN load: 0.02 TIME IN check: 1.20 TIME IN size: 0.00 TIME ...
0
votes
1answer
18 views

Check function pset5 speller

I've been stuck on this for hours, please help. bool check(const char *word) { char check_buffer[LENGTH + 1]; for(int i = 0; i < strlen(word); i++) { check_buffer[i] = word[i]; ...
0
votes
1answer
76 views

Output in Speller.c seems to match the staff solutions, but cannot seem to pass check50

This is what I happen to get when I run check50, which is weird, because when I do manual tests, I seem to match the keys. Other posts make me think this might be an issue of using the incorrect slug? ...
0
votes
1answer
52 views

lab 5 // issue when freeing family memory

Hi I have an issue with freeing the family memory in my code: when I run my code the issue seems to be from the free memory for the parents section but I am not sure what's wrong void free_family(...
0
votes
1answer
31 views

pset5 - speller - recursion

// Implements a dictionary's functionality #include <stdio.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "dictionary....
0
votes
1answer
23 views

Pset5 - Speller - Seg fault

I'm getting a segmentation fault when running this. Valgrind reports no errors, but a leak of 1,080 bytes at two blocks, with 5 allocs and only 3 free'd. Below is my load function and below that are ...
0
votes
1answer
29 views

speller is case sensitive

I tried to convert each word to lower before hashing in check, but it seems like it didnt do anything :( however, in the output the misspelled word is now lower // Implements a dictionary's ...
0
votes
1answer
17 views

speller getting different hashes in check and load

using some printf statements to debug it seems that when I hash a word in my load function I get a different value then when I hash it in my check function, even when the words are the same case. I'm ...
0
votes
1answer
20 views

My program tells me there are no words misspelled when I use the large dictionary, although the small dictionary with cat.txt seems to work fine

My code passes all the check50 checks, apart from a small amount of memory leak (I think I'm unnecessarily allocating memory to my temporary nodes). When I run the small dictionary with cat.txt, it ...
0
votes
1answer
22 views

Pset 5- Output is correct but still cant pass check50

I am currently working on Pset5, Speller. My output seems to be identical with cs50's solution (mine is simply way slower), but I still can't pass check50, it simply shows a blank window for my output....
0
votes
2answers
53 views

Segmentation Fault on Speller's Load function

bool load(const char *dictionary) { FILE *dict = fopen(dictionary, "r"); if (dict == NULL) { return false; } char word[LENGTH + 1]; while (fscanf(dict, "%s&...
0
votes
2answers
36 views

Problem freeing memory in Speller hash function

I have a problem to free the memory for the variable lowercaseword, I try to do it above the return statement with free(lowercaseword), but then the program stops working and I get errors on check50. ...
0
votes
1answer
21 views

PSET5 Load function leaking memory

I'm having a problem with memory leak, when I use Valgrind it tells me that I have 512bytes of memory leaked, I know the problem is with load because of Valgrind and because my load functions is ...
0
votes
1answer
47 views

Word array sometimes filled with weird values - Speller

My code looks like this: (ignore the comments; they're old) // Implements a dictionary's functionality #include <stdbool.h> #include <string.h> #include "dictionary.h" #include &...
0
votes
1answer
21 views

The strcsecmp() function is not working as expected

I am currently trying to solve pset5, speller. I managed to write every funtion correctly except of the check() function. This is the check() function I wrote so far: // Returns true if word is in ...
0
votes
1answer
29 views

Pset5: check returns hashtable pointers as NULL despite hashtable values printed correctly in load

My check function returns all hashtable indexes as NULL (I printed a known index of 124 and still returns NULL), despite all indexes printed correctly in load. I am not sure where exactly the problem ...
0
votes
1answer
46 views

When declaring an array of pointers that will be a hash table, do you have to set all the elements of the array to NULL?

In the distribution code for Speller in pset5, they include this line in dictionary.c // Hash table node *table[N]; Should I set every element in the array to NULL, because they are pointers? (the ...
0
votes
1answer
39 views

Struggling with PSET5 Speller valgrind problems (& possibly more)

I've been working on PSET5 for weeks now on & off and I'm becoming really frustrated. I think I'm lacking some understanding of the malloc/free relationship, I'm not sure. Here's all of my code. ...
0
votes
1answer
57 views

pset5 speller check function: cursor pointer keeps being NULL

I finished writing the code and tried to run the program, but it returned all words as misspelled. When I ran debug50 on the check function, it shows that the cursor pointer does not take the value of ...
0
votes
1answer
25 views

Trying to fix a segfault in unload , pset5, speller

So when I originally wrote my code for the dictionary.c, I forgot to create the header nodes for each 'bucket' in the hash table. It ran well when every first node of each linked list had a letter, ...
0
votes
1answer
27 views

Speller skips last word in testfile I use

The title speaks for itself, but here is a bit more in-depth explanation. While my check() function runs, it always skips the last word in whatever file it is checking out. The source code for my ...
0
votes
2answers
44 views

Segmentation fault error in pset5

I did the speller and had some errors that I solved, but now I'm stuck and need help. I debug the load and hash (I know it's not ideal, but it works:)) Now I'm receiving the Segmentation fault error ...
0
votes
1answer
47 views

pset5 speller check50 error - code doens`t handle max length (45char)

i get this error from check50 and i can t figure out why...: :( handles max length (45-char) words expected "MISSPELLED WOR...", not "MISSPELLED WOR..." everything else is green (...
0
votes
1answer
37 views

Pset5 Speller Issues with check and unload functions

I have been stuck on this pset for over a week now. I have already checked other answers to similar questions here but none have been helpful to me. Testing through check50 as well as the debugger I ...
0
votes
1answer
20 views

PSET5: Missing Words from Text and Memory Leaks

UPDATE: I just fixed the capitalized spell-checking errors. UPDATE 2: free didn't totally free the string "caterpillar". Look at image: My code seems to encounter a weird bug where it does ...
0
votes
1answer
28 views

pset5/speller Check produces a segfault if I introduce hash function

If I have a single bucket, the program runs seamlessly, however when I introduce the djb2 hash function as seen here the program produces a segfault. Here's my code with the hash function commented as ...
0
votes
1answer
33 views

Pset5 Speller. Treating the letter 's' as a valid word when using large dictionary?

I'm very puzzled my program seems to work correctly apart from one thing, when I run speller with large dictionary, the letter "s" is treated as a correctly-spelled word. I ran a test using ...
0
votes
1answer
85 views

Pset5, Speller, output the same as staff, but check50 still showing entirely errors

I'm stuck on Pset5, Speller. My code all compiles correctly, and when run on the Lala Land example, provides the same output as the staff solution (albeit mine runs more slowly). But, check50 still ...
0
votes
1answer
55 views

I dont understand valgrind pset5

Error from valgrind $ valgrind ./speller texts/cat.txt ==1453== Memcheck, a memory error detector ==1453== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==1453== Using Valgrind-3.13....
0
votes
1answer
129 views

Pset5 - Speller - memory leak?

My programme runs and I'm passing all the checks bar the last one. When I run the check with --log I get this response: :( program is free of memory errors valgrind tests failed; rerun with --log ...

1
5 6
7
8 9
24