Hot answers tagged

2

Recursive with memoization and non-recursive do the same number of computations. The recursive version however is more complex, memoization requires some check whether the value already has been calculated (the loops guarantee that), the additional function calls add some overhead, memory and time wise. The most important thing in recursion is a) defining ...


2

OK, you are pretty close, just some little syntax errors. When I try to compile your source code with clang I get the following errors, so let's solve them step by step: test.c:11:26: error: expected ';' at end of declaration int i = get_int() ^ ; You get that error because you forgot to insert a ; ...


2

If you run the code with key = "bbb" and plaintext ABC, the result is ciphertext:BACBDC. This is a mix of the properly coded BCD and the original ABC, printing alternatingly from each string. This also shows that the code is printing two letters for each letter in the plaintext. The code is structured as follows: if( <process UPPERCASE> ) {...} ...


2

Apply the %26 to the sum, not the key. Also, don't forget to apply a shift to the plaintext character (like you did in caesar), and shift the result back. And finally, non-alphabetic plaintext characters are neither encrypted nor do they trigger an increment of j. Just print those like they are. And a minor detail: Not all not fully alphabetic keywords ...


2

I tried running your code in the sandbox, resulting in an additional row without any hashes on top of the pyramid (you can see the space between the pyramid and the height prompt). To solve the problem, the first for loop should have i starting at 1 if you're using <=. for (int i = 1; i <= n; i++) Additionally, your second line of hashes have three ...


2

Get rid of the semicolon on line 6. A semicolon there marks the line as a function signature. You'll learn more about that later.


1

To check the name of the candidate in the 1st preferred coloumn only Remember, preferences[i][j]; Is simply, preferences[row][coloumn]; So, For first preference only preferences[changing_row][1st_coloumn]; Inside this cell is just a number, Use it to match the name of the candidate.


1

vote This function inputs a string a search for the names in the table of candidates, it returns true once the name has been founded or matched i.e == 0 But how? Use for-loop to iterate through the candidate_count and check the name of the candidate by using strcmp declared in string.h if (strcmp(candidate[i].names, name) == 0) { return true; } In this ...


1

Please share the code correctly so that I can help you as quickly as possible. Also tell a bit more about your problem Thanks.


1

You make a new file by clicking the green plus sign at the top, next to where it says the name of the file you are currently on. On your keyboard, then do command shift S. It will give you options for where to save the file and what the name should be. Name it pseudocode.txt and put it in your mario folder. If this helps, click the check mark or upvote it.


1

It's a new program. Start with a new file. You're done with hello.c, but feel free to look at it for any ideas on how to do anything you've done in the past. These instructions are guiding you through how to create a new directory to put that file in.


1

You don't have to create a new terminal window, but you should only start mario if you're finished with hello. If you're in the hello directory, on your terminal, execute: cd, cd pset1, mkdir mario, cd mario. Make sure it's in that order. Don't delete your hello.c work though. If this helps, please click the check mark or upvote it.


1

node *cursor1 = table[X]; int result = 0; do { result = strcasecmp(word, cursor1->word); // cursor1 is NULL here. The error messsage: Memory access error: dereferencing a null pointer; abort execution. # Reading 1 bytes from address 0x0. # # Stack trace (most recent call first) of the read. # [0] file:/musl-1.1.10/src/...


1

There's a subtle bug in here: for char in range(len(tf)): # ... char += len(str)-1 Let's say range(len(tf) = [0, 1, 2, 3, 4] and len(str) = 3. What happens if we match while char == 0 is that we will update it using char += ... to char == 2. But then the for-loop goes into the next iteration and resets it to char == 1, because that is ...


1

I noticed this a duplicate question that you have already posted here but I can't flag it as a duplicate, so I'll repost my answer here in case anyone chances upon this one instead: This is due to the new automatic GitHub authentication introduced in VSCode version 1.45. The temporary fix for this is to disable Git: GitHub Authentication in your VSCode ...


1

So let's look at the code that handles the non-signature blocks. else { // if file is open if (ftell(img) >= 0) { fwrite(buffer, 512, 1, img); } } It's supposed to discard the initial garbage blocks and write out blocks after the first signature is found. But what's really happening? First, the ...


1

for (space = 0; space <= height - row; space++) runs height - row + 1 times (+1 for having <= instead of <). For the first row, you should have height - 1 spaces, but you have height + 1. Fix that by having for example space < height - row - 1. Unrelated: height > 0 || height <= 8 makes no sense, is always true. I would not declare ...


1

I'll give you several nudges. Most of the problems arise from the nested for loop structure being off. For example, the current code writes out padding after writing out every pixel. It should only write out padding at the end of each line. Next, the code currently reads one pixel and writes one pixel, N times. It should be reading each pixel ONCE and ...


1

Check the list extract returns. Its last elements are a bit too short, as there are no len(string) substrings of length num, their number also depends on num itself. You should probably adjust your loop.


1

Let's look at the code that actually processed the image data. (I've refined the style a little to clean it up, but the code is the same.) for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++) { RGBTRIPLE triple; for (int o=0 ; o< bi.biWidth/key ; o++) { fread(&triple, sizeof(RGBTRIPLE), 1, inptr); } // skip ...


1

You can check your own style by running style50 mario.c You can see the tests used for grading by clicking the check50 button next to your submission on cs50.me/submissions With both of those tools, you should be able to figure out where you've gone wrong.


1

The code is using a pair of nested for loops. The outer loop cycles through the plaintext while the inner loop cycles through the key. That means that for EACH char in the plaintext, the inner loop will cycle through the entire key. This is a major structural error. As each char in the plaintext is processed, the code should only process at most one ...


1

Generally, you should be receiving grade feedback via email. Perhaps check your spam folders to make sure your feedback hasn't been directed there? If you can't find it, please send an email to certificates@cs50.harvard.edu with your details and someone can investigate.


1

session.clear() clears the session variables, which holds the user id, which makes @login_required think there is not a logged in user. (Notice the comment before session.clear() in the supplied login route!)


1

Recursion isn't done right. For example, your function meant to return an int might end without returning anything. Essence of recursion is that you define a base case (like for example rod of length 0 is worth nothing), and assume a sub-problem closer to that base case (shorter rod) can already be solved. Like you get a rod of length 10, and assume the ...


1

Here you replace the string with a dict: symbol = lookup(symbol) here you use symbol: db.execute("UPDATE log SET price=:price, \ total=:total WHERE id=:id AND symbol=:symbol", \ price=usd(symbol["price"]), \ total=usd(total1), id=session["user_id"], symbol=symbol) Either use another variable name (which ...


1

Where's the end of string marker \0? printf will keep printing whatever follows in memory until it sees the EOS marker, even into other areas of memory. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)


1

In this code, you see how you subtracted 'a' from the plaintext? int f = plaintext[c] - 'a'; plaintext[c] = ((f + input[e]) % 26) + 'a'; input[e] still contains an ASCII value. Want to guess what impact that has? Next, you've tied the index for the key directly to the password. What happens when non-alphas are processed? The key ...


1

I do not see where you are writing the new BITMAPFILEHEADER or BITMAPINFOHEADER to the outptr with fwrite(...) this is what caused me issue at first because I wasn't writing it properly. These things have to be written to the file first as this is what tells the computer that it is a bitmap image. I nested all 3 loops and wrote the triples as I went, but ...


1

If you array is declared with 65536 buckets, then aux_list[65536] is outside the bounds (remembering that arrays are zero-indexed). So what happens in your loop when i == 65536?


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