Questions tagged [c]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
20 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!?
1
vote
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
316 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
220 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
2k 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
593 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
41 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
25 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
49 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
56 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
117 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
213 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
48 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
42 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
69 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
54 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
6k 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
38 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
106 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
65 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
61 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
519 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) ...
0
votes
1answer
28 views

Why am i not getting an error when trying to overflow a signed integer in cs50 sandbox?

According to this question on stack overflow, signed integer overflow is not defined - https://stackoverflow.com/questions/18195715/why-is-unsigned-integer-overflow-defined-behavior-but-signed-...
0
votes
1answer
70 views

CS50 Recover image does not match

I have been working on this problem for a while but could never get it to work. Check50 says that the recovered image does not match. When I opened the recovered images manually, they are all blank. I ...
0
votes
2answers
24 views

Got into an unexpected error while compiling the code

#include<stdio.h> #include<cs50.h> int main(void) { string name = get_string("what is your name?\n"); printf("hello,%s\n",name); } When I compile the above code using command "...
0
votes
1answer
32 views

cs50 Recover segmenation fault

I am working on the CS50 Recover Problem and got stuck on the segmentation fault. #include <cs50.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { ...
0
votes
2answers
52 views

CS50 Vigenere Incorrect Output

I am stuck on this problem for days, and I have no idea about where went wrong! When I typed in /vigenere ABC the ciphertext of HELLO just becomes HFN?Z. PLEASE HELP ME! #include <cs50.h> ...
0
votes
1answer
123 views

Finished Mario week 1, but unsure if it's a proper solution

So I managed to get the intended result for Week 1 problem set 1 Mario (less comfortable), but I'm not sure if my solution would be considered good code. In line 11, is it ok to have subtracted by 1? ...
0
votes
1answer
41 views

Trying to understand the insertion sort algorithm

While I was working on the PSet3, I've realized that I don't really understand the insertion sort algorithm the way it is presented in one of the short CS50 videos. So I commented out each line of ...
0
votes
1answer
28 views

PSet3 helpers.c fails one of the checks

I'm working on the PSet3 Find problem. Here's my code for the sort and search functions: bool search(int value, int values[], int n) { if (value < 0) return false; else { ...
0
votes
1answer
111 views

Rewrite method in Resize (less) is printing wrong large.bmp

So my small image is resizing vertically but I get all the wrong colors. Can someone take a quick peek at my rewrite method to see where I've gone wrong? I've attached a pic of my large.bmp passing in ...
0
votes
1answer
97 views

pset 2 caesar help!

am having trouble printing the correct ciphertext, code is rather lengthy for sure but will appreciate it a lot if anyone can tell me what's the problem here! For example with a key of 1 and a ...
0
votes
1answer
53 views

pset3 recover is fopen changing the first value in my buffer?

My code for pset3 works and recovers all the images as it is supposed to however I realised that when I call fopen the first value in my buffer array becomes 0 I fixed this by changing the value back ...
0
votes
1answer
15 views

What error is resulting in incorrect values for change?

My code follows: // include all necessary header files #include <stdio.h> #include <cs50.h> #include <math.h> // define all coin values #define QUARTER 0.25 #define DIME 0.10 #...
0
votes
1answer
40 views

Why did I miss a style point on Fahrenheit?

Here is the code I submitted: // include all needed Header files #include <stdio.h> #include <cs50.h> int main(void) { // prompt user for Celsius value float celsius = get_float(...
0
votes
2answers
21 views

does function prototype effect's speed of c terminal?

I am watching cs50 lecture 1 C. following the lecture, I got curious about the function prototype. tutor mentioned it as convenient and traditional to use it. but for computer side - Isn't difficult ...

1 2 3
4
5
11