# Tag Info

Accepted

### variable used in loop condition not modifies in loop body

Well, I had to think carefully about what the code is doing. That mostly comes from not using a best practice. Here's the best-practice guideline on whether to use a FOR loop or a WHILE loop. When ...
• 68.7k
Accepted

### PSet 4 - Recover. The first picture (000.jpg) doesn't get recovered, all other images do (049.jpg is the last image recovered)

Simple logic error. Look at the following: { if (number != 0) { fclose(output); sprintf(name, "%03d.jpg", number); output = fopen(...
• 68.7k
Accepted

### What's the most efficient prime-finding algorithm? (Week 1 Practice Problems)

You can likely google it to find out. But the first thing that comes to mind is to lower the high limit of numbers to check. Simply put, if you're checking whether N is a prime, you need only see if ...
• 68.7k

### recursive atoi | CS50

In C all variables must be declared at the top of the body of a function they can't be declared later. int convert(string input) { int length = strlen(input); int temporaryInt = 0; // declare it ...
• 1,091
Accepted

Actually, as written, it does print the largest number, but only from sheer coincidence. The largest number in the array is 6, which is also the first number. Since the loop only runs once, it's ...
• 68.7k
Accepted

The problem is that you are freeing the wrong thing entirely and doing it incorrectly. You need to free EVERYTHING you malloc, and the things you malloc are being stored in plates, p is just one of ...
• 1,091
Accepted

### Recover PSET 4 Week 4 - skipping while loop

First of all, are you sure that you remembered to recompile/make a new executable from the new source code file? The while loops are working fine. When I test the code, it's generating the correct ...
• 68.7k

### variable used in loop condition not modifies in loop body

The problem is that you are putting semicolons ';' at the end of your for loops. That makes them just evaluate the expression in the loop and so each would just be an infinite loop. that's bad.. you ...
• 1,091

### CHECK50 Passes, but I Get 6/7 When Submitting

check50 is timing out because your program takes longer to run than is allowed. It comes down to this Your buffer is unsigned char *buffer = malloc(512); Your fread is fread(buffer, 1, sizeof(buffer), ...
• 18.6k
Accepted

### Problem Set 2 (Scrabble) / Variable Scope

First: you shouldn't do this global variables, and you really can't for reasons you will see. Second: The problem is that you are not actually 'using' your global variables in your function call ...
• 1,091
Accepted

### PSET 5 speller segmentation fault when trying to run

Start by putting breakpoints at the first line in each function to see which function is failing. (Hint: If program gives "MISSPELLED WORDS" heading, it has completed load.) After that, it'...
• 28.4k

### CS50x PSET1 Credit <class 'pexpect.exceptions.EOF'>

From the spec: your program’s last line of output [should] be AMEX\n or MASTERCARD\n or VISA\n or INVALID\n, nothing more, nothing less. This program will print "something more" if the ...
• 28.4k
1 vote

### CHECK50 Passes, but I Get 6/7 When Submitting

As my comment mentioned the main issue I see is that you have some logical errors in your code that should be fixed, and your read is also not of the proper size because you used sizeof(buffer) which ...
• 1,091
1 vote

### How to merge sort array of struct while maintaining relations between int array and char array

each instance of nameandnum is a complete object, when you do your merge sort you need to swap the whole objects not just the buffer field.
• 1,091
1 vote

• 11
1 vote

### hey im on pset2 readability. i cant seem to get the right output. it is supposed to show letters= and words= but its not

You are using n as a bounds for your loop in counting the words, but n was assigned the value 1. You would most certainly want to use letters instead. Given these problems I would suggest that you ...
• 1,091
1 vote
Accepted

### Problem with my code (Problem Set 1 - Credit)

This is one of those cases where the error really doesn't tell you what was really wrong. Let's look at that line: for (;n > 0 ; i++) This is a for statement. It requires 3 parts - the ...
• 68.7k
1 vote

### psets2/scrabble.c, In pset2, scrabble im running into an error incompatible comparison between type int and char

The problem is that word is a string and that indices of word are char's not int's and POINTS is an array of int's. You need to do something to the result of word[i] to turn it into an integer, where ...
• 1,091
1 vote
Accepted

First, understand that compilers are dumb but thorough. Let's take a close look at the function: int count_letters(string text) // Calculate number of letters { int LC = 0; for (int i =0 , n =...
• 68.7k
1 vote
Accepted

### Credit : the checksum is correct for <10 digits, but for14,15,16 digits getting negative checksum

this is in need of major cleanup. organize your code and avoid repeating yourself. For example figure out how many digits are in the number once. save that value. Figure out the value of the i-th ...
• 1,091
1 vote

### pset4 blur; artifacts on a white parts of an image

I wrote my algorithm as @UpAndAdam said. It's much easier to read, looks cleaner and now computes new pixels' values from an input image, not from modified image. void blur(int height, int width, ...
• 27
1 vote
Accepted

### pset4 blur; artifacts on a white parts of an image

You are not capping the value of the average to 255 as you are supposed to. You need to take the final value to be the minimum of the average for the color and of 255. otherwise you are going to get ...
• 1,091
1 vote

### Practice Problem 4: error: incompatible pointer types passing 'char *[7]' to parameter of type 'char *' [-Werror,-Wincompatible-pointer-types]

No, you are incorrect. If that's what you want then you need to define plates as char plates[8][7] you want 8 char arrays of length 7. With what you declared you have a pointer to 8 arrays of 7 chars....
• 1,091
1 vote
Accepted

### pset 5 speller do not pass check 50

if you are going to use strcmp and not basestrcmp (or whatever it was) you need to make sure you convert all dictionary words and all in put words to lower case, ( or all to uppercase ) you are only ...
• 1,091
1 vote
Accepted

### error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char*'...printf (y)

The problem is incorrect syntax for a printf call. It should look like this: printf("%i", y); You can't just tell printf to print a var. Instead, there has to be a formatting string with ...
• 68.7k
1 vote
Accepted

### pset5 speller cannot read number of word in dictionary

Your size function is fundamentally broken as pointed out by @DinoCoderSaurus, you are making a completely invalid assumption. That your code sometimes outputs the same answer as the staff solution ...
• 1,091
1 vote

### Pset5 Speller - Weird Load Function Bug (Edited w/ Code)

I suspect that this problem exists with each and every linked list that the table[] elements point to. (i.e., if the hash value is the first letter of each word, the first word in the dictionary file ...
• 68.7k
1 vote
Accepted

### Stuck in mario-less directory in terminal CS50

You understand that you have to click on the mario.c frame to start typing and entering code in the file, right? In the image you posted, this would be the frame with the lone number "1" ...
• 68.7k
1 vote
Accepted

### How to Solve : expected identifier or '('

I'm thinking it has something to do with "break" being a keyword (like "for", "while", "continue", etc.) that shouldn't be used as a variable. Try using a ...
• 68.7k
1 vote
Accepted

### PSet5 Speller: Are we hashing the words in the dictionary into a hash table or the words of the text?

the purpose of the hash function is to calculate a hash value for a given word and return that value. Nothing more. The table[] array (or whatever you name it) is an array of pointers to the first ...
• 68.7k

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