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
12
votes
1answer
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.............................................
9
votes
1answer
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?
8
votes
2answers
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....
8
votes
1answer
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 ...
7
votes
1answer
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 ...
6
votes
1answer
70k 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 ...
5
votes
3answers
2k 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 ...
5
votes
2answers
358 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 ...
5
votes
1answer
965 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 ...
4
votes
2answers
5k 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 ...
4
votes
1answer
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?
4
votes
2answers
3k 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 ...
3
votes
1answer
2k 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.
3
votes
1answer
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 ...
3
votes
2answers
103 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 ...
3
votes
1answer
721 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 ...
3
votes
1answer
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 ...
3
votes
3answers
894 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 ...
3
votes
1answer
267 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 ...
2
votes
2answers
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 ...
2
votes
1answer
730 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 ...
2
votes
1answer
877 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 ...
2
votes
3answers
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));
2
votes
2answers
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 ...
2
votes
1answer
1k 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 ...
2
votes
3answers
1k 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 ...
2
votes
2answers
403 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?
2
votes
2answers
450 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.
2
votes
1answer
930 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.
2
votes
1answer
85 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 ...
2
votes
1answer
177 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 ...
2
votes
2answers
121 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 ...
2
votes
1answer
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 ...
2
votes
1answer
764 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()...
2
votes
1answer
348 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 ...
2
votes
2answers
5k 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 ...
2
votes
1answer
95 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 ...
2
votes
1answer
323 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 ...
2
votes
1answer
862 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 ...
2
votes
1answer
73 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 ...
2
votes
1answer
120 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....
1
vote
2answers
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, ...
1
vote
2answers
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 ...
1
vote
1answer
1k 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 ...
1
vote
1answer
458 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 ...
1
vote
1answer
587 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]...
1
vote
2answers
155 views

How to build a “.raw ” image of a storage media?

In pset 5 David gave us his SD card's card.raw file to recover deleted JPEG images from. What are these .raw disk images and how can we build them to create practice problems similar to pset 5 for ...
1
vote
1answer
3k views

Cannot figure out what is wrong with recover - “Improper call to JPEG library in state 201”

Does anyone know why I might be receiving this error in my recover program? I've used xxd to confirm that the first four bytes are correct and signal that each is a jpeg. However, I am still receiving ...
1
vote
2answers
175 views

Trouble incrementing the number in jpeg filenames

I've gotten recover to work... sort of. The problem is difficult to describe without posting my code, but here's an attempt: My program can find all the jpg signatures (in GDB, my jpeg-finding line ...
1
vote
1answer
48 views

pset 5 The dictionary pointer, why is it a char*?

Just wondering, why is the dictionary pointer passed into load a char* instead of a file pointer? Since the dictionaries to be loaded are files.

1
2 3 4 5
24