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
13 votes
1 answer
3k views

check50 returns unexpected end of input

I recently finished my code for pset5 recover.c. It compiles, and runs successfully and recovers all 50 pictures. But when I try check50, it gives Checking.............................................
DivineArtist's user avatar
10 votes
1 answer
3k views

Surprise with GDB way of reading bfType BMP headers

Why if i check with the xxd an image eg. small.bmp the bfType is 0x424d and when you run copy in GDB the value of bf.bfType is 19778 and the program "copy" in line 55 check with 0x4d42. Is it reading ...
dizcola's user avatar
  • 121
10 votes
1 answer
4k views

How to Update bfSize in resize?

In resize problem, we have to update the headers of image. Which attributes should be updated and how do i update bfSize attribute?
HKH's user avatar
  • 150
9 votes
2 answers
2k views

How does fread progress through each byte in copy.c?

In copy.c (and the other apps using the same start code), how does freed know to read one byte after another? It seems to just do it automatically. Eg, this will read each byte, from first until bi....
Noah's user avatar
  • 193
8 votes
1 answer
8k views

What is the difference between bfSize and biSizeImage?

I'm working through pset5's resize right now and I'm at the point where I've got to update the headers for the new file. I'm having trouble computing them, mainly because I can't really tell the ...
Enrico Tuvera Jr's user avatar
6 votes
1 answer
108k views

How to fix the "conditional jump or move depends on uninitialized value" valgrind error?

Need help again. I've got my linked list working. It copies a list of words from a file into a linked list. Now I want to make a hash table so that all words starting with the letter 'A' go into a ...
jzz's user avatar
  • 65
6 votes
3 answers
3k views

Explanation of the formula for padding

This is the formula given for padding in PSET5 from WEEK7 : int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; I don't understand what the outermost %4 is meant for. It seems redundant ...
user1580's user avatar
5 votes
2 answers
12k views

Conditional jump or move depends on uninitialised value(s)

I just finish debugging my code for pset5 dictionary.c, It's working correctly, It passed check50 too. Now the problem I am encountering is in valgrind my heap is all freed, But wherever in ...
Vipin kumar's user avatar
5 votes
2 answers
367 views

Why Are There Some Missing Psets and Weeks?

So, i just finished the continued lecture on week 5, and then I was going to make the pset 5, but I noticed that it is on Week 7 page, and I noticed that there is no week 6 page, is that normal? Or ...
Joao Turolla's user avatar
5 votes
1 answer
984 views

Pset5: Misunderstanding tries and method to assign letter to an array inside a struct

Before posting, I've searched a lot here and there on the Internet to find the answers to my questions myself and I did code something that eventually works. My issue is that I've re-rewrote some ...
DFATPUNK's user avatar
  • 155
4 votes
1 answer
3k views

What data structure do you use to store the buffer in recover?

What data structure do I use to store the 512B blocks in a buffer? Thinking about an array or ints? Or am I completely off?
Jesse's user avatar
  • 157
4 votes
2 answers
5k views

PSET5: trie -> initializer element is not a compile-time constant

I want to declare a root node and have done the following. typedef struct node { bool is_word; struct node *children[MAX]; }node; node *root = malloc(27 * sizeof(struct node)); When I try ...
Salamit's user avatar
  • 231
4 votes
2 answers
886 views

Debug50 is not functioning properly

I was using debug50 over and over for pset5 speller and at some point it just stopped working. Now when I try to use it with simple programs it still won't work. I've restarted the ide from inside ...
Edwin Thomas's user avatar
4 votes
1 answer
2k views

What Does __attribute__((__packed__)) Do?

I understand the idea that each scanline should have a number of bytes that is a multiple of 4. Otherwise, the BMP is stored in a such a way that each scanline is padded with as many zeros as it takes ...
kzidane's user avatar
  • 17.7k
3 votes
1 answer
3k views

pset5 getrusage in speller.c

What are "before" and "after" used in getrusage? Why and how they are used? I also find manuel's explanation about RUSAGE_SELF hard to understand. Thanks in advance.
eifphysics's user avatar
3 votes
1 answer
5k views

Cannot use make: "Nothing to be done for whodunit.c"

For pset5 I did as suggested and copied copy.c to a new file named whodunit.c. I've left everything the same but hopefully changed the red pixel values. When I go to compile using make I get this ...
Anna Burck's user avatar
3 votes
3 answers
1k views

Proper use of fread function

I have declared a buffer as follows : unsigned int buffer[512]; Now, later on in my code I used fread in the following manner fread(buffer, 512, 1, infile) and everything worked as expected. Note ...
Aditya Kashyap's user avatar
3 votes
1 answer
1k views

pset 5 resize vertically - use of fseek

I am struggling with the vertical resizing using the recopy approach. I read a pseudocode in an answer to another question in this forum and am trying to code it. I feel I am near but something is not ...
Federico's user avatar
  • 111
3 votes
1 answer
271 views

Code in speller.c

In speller.c, the line 89 is : while ((c = fgetc(fp)) != EOF && isalpha(c)); but shouldn't it be : while ((c = fgetc(fp)) != EOF && (isalpha(c) || c == '\''); because a word can ...
jaja360's user avatar
  • 31
2 votes
2 answers
1k views

pset5 copy.c confused in fread

in copy.c i am seeing some weird code in the part of iterating the scanline and pixels. Since we are passing "inptr" to the (fread) and telling it to work just once. How does the code makes sure that ...
Milan's user avatar
  • 55
2 votes
1 answer
6k views

CS50 good hash function for PSET5 Speller

I was looking up different hash functions and was getting really confused following what the code was doing. I stumbled upon this hash function: int hash(const char * str) { int hash = 401; ...
ayeeitsalpha's user avatar
2 votes
1 answer
847 views

What exactly does getrusage do? Pset5

I'm new to this, so this may sound stupid. // determine dictionary's size getrusage(RUSAGE_SELF, &before); unsigned int n = size(); getrusage(RUSAGE_SELF, &after); // calculate time to ...
Vaish MK's user avatar
  • 167
2 votes
1 answer
1k views

PSET5: char word[LENGTH + 1];

Hello, I am just starting out on pset5 reviewing the speller.c code. Looks pretty straightforward however I don't entirely understand the following variable declaration: char word[LENGTH + 1]; So I ...
GRN's user avatar
  • 23
2 votes
3 answers
2k views

what does `while ((c = fget(fb)) != EOF && isalpha(c))` does?

what does that line do in speller.c? while((c = fget(fb)) != EOF && isalpha(c));
kawegan's user avatar
  • 76
2 votes
2 answers
4k views

Pset 5 - Resize

I'm having problems with the header manipulation. My code seems to factor well images but it doesn't calculate well bi.biSizeImage and bf.bfSize. This is what I've done: // read infile's ...
FranGoitia's user avatar
2 votes
1 answer
2k views

How to know how many buckets for hash table - Speller PSET5

I am implementing the hash table for load at the moment, but I don't know how I should figure out how many buckets I should be using. Is there a 'rule' for this when creating hash functions, or is it ...
Davis's user avatar
  • 144
2 votes
3 answers
2k views

PSET5 Speller, faster check and load times hashmap

I am working on the hashmap implementation for the PSET5 Speller problem and seem to keep encountering problems. I have already created a couple of other solutions to the problem (a-z style hashmap ...
Zach B's user avatar
  • 31
2 votes
2 answers
418 views

Is it possible to see the actual bytes of card.raw?

Is it possible to see the actual bytes of card.raw from pset5?
Dusan Milosevic's user avatar
2 votes
2 answers
518 views

pset5 speller how to only use 7.4 kb memory?

I found in the Big Board (Spring 2018) that some people only used 7.4 KB memory (as highlighted), while the dictionary contains 140k words. I don't understand how that's possible.
David H. J.'s user avatar
2 votes
1 answer
348 views

Pset5 Speller Valgrind error

I got Pset5 Speller to work correctly but I am getting a Valgrind error as follows 568 bytes in 1 blocks are still reachable in loss record 1 of 1: (file: dictionary.c, line: 108) for all the words. ...
noob's user avatar
  • 23
2 votes
1 answer
941 views

pset 5 load function how to implement it?

Hi can somebody can help me in understanding pset 5 on how to implement load function using a hash data structure.I can't understand how to implement it.
superhuman's user avatar
2 votes
1 answer
32k views

PSET5 compiles but gives: "free(): double free detected in tcache 2" error on testing

Been scratching my head at this for a while now. I use FREE() only once in the program, and don't know why I get this error. Any help is appreciated :-) // Implements a dictionary's functionality #...
General Noob's user avatar
2 votes
2 answers
4k views

stuck on speller Load function

I am stuck on the load function for speller. I don't quite understand how to insert word into a linked list. This is what I have so far: // Loads dictionary into memory, returning true if ...
Joe Joe Joe's user avatar
2 votes
1 answer
88 views

PSET5 Speller / Dictionary - Seg Fault and Incorrect Check

"debug50 ./speller texts/alice.txt" doesn't return a segfault. It runs to completion. But "./speller texts/alice.txt" returns a segfault. Can I PM someone my code to take a look at? Why would running ...
Spenny Davis's user avatar
2 votes
1 answer
191 views

CS50 PSET5 Won't Work With Apostrophes

I was testing my program with different texts and I found out that my code lists all words with apostrophes as misspelled, even though I have an if statement in my load function that checks for any ...
SuperNovaCoder's user avatar
2 votes
2 answers
132 views

how effective would it have been to use an array for the dictionary?

I just completed pset5 using a trie, but I'm curious about other methods. How effective would it have been to load the dictionary into an array and then use a binary search function to locate words ...
736f5f6163636f756e74's user avatar
2 votes
1 answer
1k views

Can't recover 049.jpg successfully

The 049.jpg file is created but not recovered! I have used the fread function to detect the EOF as told in the walk through by Zamyla. Here is a link to the check50 sandbox output. # Checks 0 ...
Chelian's user avatar
  • 23
2 votes
1 answer
932 views

How is staff solution so fast in load and unload?

I have implemented dictionary as a trie and it's working fine. Check50 okays it, so does valgrind. Now, comparing the running times, my check() is as fast as the staff solution, but load() and unload()...
Marek Jedliński's user avatar
2 votes
1 answer
379 views

CS50 PSET5 Memory Leak (updated)

I had posted a question here two days ago regarding memory leak in problem set 5 and haven't had it resolved yet. Please refer to my question, available here: CS50 PSET5 Memory Leak (please note that ...
Alex Chan's user avatar
  • 121
2 votes
2 answers
6k views

pset5 speller.c check

Hi I'm tackling CS50's pset5. I am trying to implement speller and I got stuck on check part. I implemented load via hashtables and whole dictionary loads up correctly,when I'm using smaller text ...
Nedeljko Zekonja's user avatar
2 votes
1 answer
103 views

Why should we assume that the size of the output BMP file does not exceed 4 GB?

Per the spec of pset5, You’re welcome to get started by copying (yet again) copy.c and naming the copy resize.c. But spend some time thinking about what it means to resize a BMP. (You may ...
RexYuan's user avatar
  • 309
2 votes
1 answer
330 views

Recover creates an unreadable image file and then segfaults

I am pulling my hair out over recover.c in pset5. My code manages to generate 1 appropriately named (but unreadable) jpg and then fails with segmentation fault. I have tried to figure it out by ...
Alexandra's user avatar
2 votes
1 answer
1k views

pset 5 check function

I used hash table to store dictionary in pset5. In order to minimize run time, I chose to cite a hash function online instead of writing my own hash table of maybe 26 rows for 26 letters. I wrote the ...
Xuying Shao's user avatar
2 votes
1 answer
75 views

How will I know that I uploaded the dictionary sucessfully?

I have just implemented the load function for dictionary, I am just confused right now as to how to check speller if my load was a success, I made the load function on a seperate file and edited the ...
Furrukh Jamal's user avatar
2 votes
1 answer
126 views

How do I make dictionary.c compile with strings.h?

There seems to be a useful function -- strcasecmp -- in the strings.h library (notably different from string.h). However, when I try to amend this to my header information (e.g., #include <strings....
Richard's user avatar
  • 166
1 vote
1 answer
2k views

Speller.c appears to be working but is case sensitive (can't recognize capitol letters)

I'm getting my spell checker to load and check. It appears to work (as far as I've tested thus far) except for I can't get it to be case insensitive. I've tried a couple of approaches, but in both ...
Brandon Terry's user avatar
1 vote
2 answers
3k views

Try to use trie in pset5

I know if I want to use trie in pset5 to load the dictionary, there should be a struct containing an array of pointers for the alphabets or the apostrophe and a variable of bool. The question is, ...
Y_C's user avatar
  • 115
1 vote
2 answers
3k views

How to interpret biHeight data

I am having trouble with biHeight from the header info of bmp files. In the file small.bmp, from pset5, that is 3X3 pixels: biHeight has the value fffffffd. I would expect it to be the same as the ...
Touten's user avatar
  • 23
1 vote
1 answer
544 views

Pset5 getrusage second call speller.c

I would be grateful for help on correcting or confirming my understanding of the second call to getrusage function in speller.c. The first call assigns certain values to both before and after ...
Vitale's user avatar
  • 235
1 vote
1 answer
603 views

pset5 root node defitnion (trie)

I'm trying to figure out where/how to define the root node of my trie in dictionary.c. I have declared my struct node as follows: typedef struct node { bool is_word; struct node* children[27]...
jiewpeng's user avatar
  • 115

1
2 3 4 5
26