Questions tagged [c]

The tag has no usage guidance.

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

How to stop terminal process in CS50 Sandbox? (I've tried Ctrl-C and Ctrl-\)

I'm doing problem set 1 on the CS50 Sandbox, and have ran into some infinitely running programs. When I do ctrl-c or ctrl-\ (I am on mac and have tried both cmd and ctrl), the process still continues ...
1
vote
1answer
755 views

CS50 - Filter - Reflect Image

I am working through CS50's PSET #4, specifically filter -> reflect. I can get the image to present correctly (i.e., it is mirrored), but it is not exact enough to pass the CS50 Check. My code is as ...
0
votes
1answer
66 views

pset4 recover: 'recovered image does not match'

My program recovers the images but the recovered images are all blank and check50 says that they "don't match". All the images are 512 bytes in size. Please help me find out why this is happening. My ...
0
votes
1answer
75 views

pset4 Recover 049.jpg does not match, even though it opens correctly as an image

So, I've been struggling with this bug for a couple days now and can't seem to figure out how to fix it. I've also noticed that the final image file is WAY larger than any of the other jpg's my ...
0
votes
1answer
321 views

Readability in C passes tests on instructions page but when submitting, only 2/11 pass

I've written all of my code and tested that the letter, sentence and word output is counting correctly, which it seems to be. I even tested with all of the sentences on the instructions page and that ...
0
votes
1answer
29 views

How to swap strings?

The main problem comes when we swap strings of unknown lengths. Lets say we have two strings assigned to two variables say a, b. Now if I use a temporary string say c, and use strcpy(c,a), then use ...
0
votes
1answer
579 views

pset4 - filter - sepia: Only red value is consistently correct

So, I currently have this solution for the sepia function of the filter problem. void sepia(int height, int width, RGBTRIPLE image[height][width]) { int b, g, r; // Apply sepia algorithm to ...
0
votes
1answer
365 views

Speller Valgrind leaks bytes + error: munmap_chunk(): invalid pointer error in C

Check50 gives me the munmap_chunk: invalid pointer - it seems I am not copying something right with strcpy. Valgrind gives me: LEAK SUMMARY: still reachable: 608 bytes in 2 blocks ==2864== 56 bytes ...
0
votes
2answers
530 views

Pset2 Readability: Grade calculation wrong

I have just finished doing the Readability problem in pset 2, everything computes correctly except for the final grade. It is always around the -15 or -16 mark. Below I have added only the code I ...
0
votes
1answer
165 views

Plurality - check50 issue

Hoping for some insight on this.. code works perfectly fine, prints correctly when testing in terminal, but for some reason check50 outputs errors once it starts printing winners. Would love to find ...
0
votes
1answer
29 views

Why am I keep getting a segmentation fault in my code for speller every time I run it?

According to valgrind, it says lines 40 and 87 are creating this error. // Implements a dictionary's functionality #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #...
0
votes
1answer
247 views

pset3 runoff segmentation fault problem

I am doing the 2020 version of CS50's pset3 and I am already stuck (again) at the runoff voter function. My code below resulted in segmentation fault. I don't know how to fix this though. So here's ...
0
votes
2answers
24 views

Why does this error keeps popping in my caesar code?

I am doing the caesar exercise for PSET 2 and this is my code: #include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int main(...
0
votes
1answer
528 views

Plurality fails to compiles

I always work on Psets on my local machine and replace string with char * so I don't have to use the CS50 library in my header files. This is the only explanation I have for why my code doesn't ...
0
votes
1answer
24 views

Can I use if-statement or switch-statement instead of a for loop!

I just want to know if it is possible to use conditions instead of loop in the problem set 1 (Mario), because I think that it's easier to get to the intended output without much code!?
2
votes
2answers
1k views

pset3 (runoff) keep getting print_winner error when using check50

I keep getting these errors when running check50 on my runoff program: print_winner prints name when someone has a majority print_winner did not print winner of election print_winner returns ...
0
votes
2answers
2k views

RUNOFF PSET3 - bool is_tie(int min) function gives an error in Check50 unable to remove

I have tried a number of ways to execute the code in bool is_tie function; however, I always seem to receive the same error in check50. I have run the code through debug50 and it seems to work ...
0
votes
1answer
320 views

pset2 - Readability: Math not working properly

For the large sentence test of pset2's Readability task, I was constantly getting Grade 8 instead of Grade 7, even after checking the counting went properly. After roughly an hour of debugging I've ...
0
votes
1answer
272 views

valgrind memory leak on speller linked list..."blocks are definitely lost..."

I'm working on my memory leaks for the load() function. Valgrind give me the following error message ==1675== HEAP SUMMARY: ==1675== in use at exit: 8,011,640 bytes in 143,065 blocks ==1675== ...
0
votes
1answer
3k views

speller valgrind "uninitialized error was created by heap allocation"

I'm running valgrind on my speller for a hashtable. One of the errors I get, I'm not sure I understand is uninitialised value was created by a heap allocation ==3079== Uninitialised value was ...
0
votes
1answer
600 views

Failure in Readability code

I'm having an issue with my code for pset2, Readability. My code so far is: #include <cs50.h> #include <stdio.h> #include <string.h> #include <ctype.h> int main(void) { ...
3
votes
4answers
2k views

Pset2 Readabilty: Why are my grade levels calculating incorrectly?

For Pset2: Readability, I'm writing a program in C that prompts the user for text input, analyzes how many letters, words, and sentences are in the text entered by the user, and calculates the grade ...
0
votes
0answers
35 views

CS50IDE Debugger quits at random times

I'm having having trouble with the debugger just vanishing at random points in my code. Its different points every time and will go right past if i start again. Anyone elese had a similar problem?
0
votes
1answer
1k views

error: result of comparison against a string literal is unspecified (use strncmp instead) and Check50 showing error on credit problem

I've submitted my credit problem after testing with possible values and everything seems to work just fine as planned, except that I got some errors that certain numbers could not be tested as INVALID ...
0
votes
1answer
44 views

Why is this generating wrong output and Runtime - out of bound error?

I have a program below, which gets some random numbers from users and then multiply every second to the last digit by 2, stores it into an array and print out the value of each array index. It seems ...
0
votes
1answer
27 views

crack, Different passwords produce the same HASH

i have a hard time understanding the crypt function and since there aren't any technical details of how it works out there, i tested it and i observed that it is producing the same hash for different ...
0
votes
1answer
52 views

on pset4 speller load() struggling to understand if populating dictionary correctly and how to check hashtable

I am building my load() function and I'm wondering if I'm building it so that it is indeed storing the dictionary words correctly. I tried printing both: printf("%s\n", new_node->word); //to see ...
0
votes
1answer
58 views

What is probably wrong in this while loop?

I'm getting positive integers from users. I used a do-while loop to check and validate that the user input is: 1. A positive integer. 2. The length (I.e size) is between 13 and 16 digits BUT NOT ...
0
votes
1answer
4k views

2019 CS50 PSet 4 Filter Less

https://cs50.harvard.edu/college/psets/4/filter/less/ I'm so lost I don't really know where to begin. The last exercise plurality with the distributive code was a nightmare, I only found one other ...
1
vote
3answers
128 views

Why is this while loop generating errors

I'm trying to get a 15 or 16 digits numbers (integers) from users and then using a do while loop to check if the user entered a valid number, otherwise, they will be re-ask to enter the number. THE ...
0
votes
1answer
234 views

check function in speller pset5, not quite understanding the apostrophe

I am working on the check() function of dictionary.c. I am using it to test cat.txt: A cat is not a caterpillar. It says everything is correctly spelled except "not" When I check the hashtable ...
0
votes
1answer
51 views

Pset3-resize explaination

I am struggling to understand how to approach resize problem. I see there are alot of codes available for me to use directly. I do understand the problem, Zymal's pesudocode, but the lack of clarity ...
0
votes
1answer
51 views

PSET3 -I am getting segmentation fault

I am getting seg fault over and over again. Could anyone help out please. I am pretty sure the functional part of the code, the while loop, should be working properly. Thanks in advance. #include &...
0
votes
1answer
38 views

Segmentation fault on PSET3 recover

My program compiles, but wherever it runs I recieve a segmentation fault error. However i cannot see where the source of the problem is: #include <stdio.h> #include <stdlib.h> #include &...
0
votes
1answer
44 views

pset1:credit, multiplication problem

for some reason my program doesn't multiply (card_number % 10) * 2 for example when card_number % 10 = 6 the output is 6 instead of 12. for(int x = 0; card_number != 0; x++) { if (x % ...
0
votes
1answer
71 views

Pset4 - Recover: Weird output

This problem set is the worst and it made me cry 🤣 Take a look at this code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { // ...
0
votes
1answer
55 views

writing pixels n times to array

i'm struggling trying to figure out how to store pixels n times to an array for (int i = 0, biHeight = abs(oldheight); i < biHeight; i++) { // iterate over pixels in scanline for (...
0
votes
1answer
1k views

Pset3: Tideman - sort_pairs error!

I have difficulty to understand what should the output of the function sort_pairs() should be!, What I understand is I should take the unsorted pairs[] and sort it. For example, this is pairs[] ...
1
vote
3answers
5k views

Pset 2: Finding out readability level using Coleman-Liau index using C (CS50 2019)

I am currently stuck at a problem for a few days to find out why it's happening. I am writing a program to find out number of letters, words, and sentences. Using these values, I am using Coleman-...
2
votes
1answer
7k views

Pset3: Plurality - Weird output!

This program is for counting the plurality for a list of candidates, Check Description for more info, The program works like this: Enter the candidate's name as an argument when running the program ...
0
votes
1answer
18 views

Arrays and their sizes in C

I am having problems related to arrays and their sizes in C. There's something I am doing wrong, but I don't know what exactly. Here is a sample of the code: #include <stdio.h> #include <...
0
votes
1answer
53 views

Resize pset4 - Can someone check my code

Please someone help me with my code. I think that problem is the fseek function. I don't know how to calculate the number of bytes needed to be skipped. I obtained wierd images with distorted collors. ...
0
votes
1answer
44 views

PSET4 resize recopy method. Help me understand

I don't exactly understand the principle of recopy method used in resize pset4. Can someone explain me without giving the actual solution. Here is my code so far. After running the code I recive a ...
0
votes
1answer
86 views

PSET3 resize vertically help

I'm struggled for 12 hours on resize problem. After trying for so long i reach to this result. The smiley BMP file looks well but it doesn't seem to be fully resized. When i try to resize small.bmp ...
0
votes
0answers
39 views

I don't understand how to change header info and how it is implemented

I don't understand how the new image will implement new data i imput in like new_biWidth or new_biheigh. I added this new variables in bmp.h and I asigned to them same tipes of data like the old ones. ...
0
votes
1answer
112 views

I'm stuck on cs50 pset2 - crack

I am new to coding. I am trying to solve crack problem of cs50. The problem works hashing 1 character, but when i try to hash 2 characters i can't pass arguments from the string to the crypt function. ...
0
votes
1answer
70 views

Pset4 'Recover' - Help! How can I solve this segmentation fault?

For pset4 'Recover', I'm facing a segmentation fault but I cannot find what I did wrong in my code. If I use echo$? to find where the bug is, it returns the value 1. Can someone help me to point me in ...
1
vote
0answers
62 views

CS50, pset2, crack, suggested dictionary file

I am taking cs50 on edx and I am currently on pset2, crack. I want to find a dictionary file that has a fair (maybe over 50,000?) amount of words in it to encrypt and compare them with the hashed ...
0
votes
2answers
603 views

While Loop in C only executing once and then stopping

I have created a function in C that tests if an integer in between a range of 100 (min) and 500 (max) - The function calls on another function called "getInt()" which tests whether the integer is ...
0
votes
1answer
54 views

jpg's are not proper, mix of multiple images. Can anyone tell me whats wrong?"RECOVER"

here is my code while (fread(buffer, 512, 1, inptr) == 1) { if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0) ...

1 2 3
4
5
12