Questions tagged [c]

The tag has no usage guidance.

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

i m getting segmentation fault in my code for cs50 caesar

#include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int main(int argc, string argv[]) { //getting correct input for KEY ...
0
votes
1answer
10 views

when I compile my program this bug appear. error: control may reach end of non-void function [-Werror,-Wreturn-type] }

bool check_valid_key (string s) { for (int i = 0, len = strlen(s); i < len; i++) { if (!isdigit(s[1])) return false; return true; } }
0
votes
1answer
29 views

CS50 Week 4 Recover. Generating 50 Blank images

Here is the code any help is greatly appreciated. Thanks! #include <stdio.h> #include <stdlib.h> #include <cs50.h> #include <stdint.h> #include <stdbool.h> typedef ...
0
votes
1answer
8 views

Find hex values inside a string in C?

I have a long string "given_string", and I'm trying to find hex values within that string. Here's a simplified example: /* Find a sub-string in a given string: */ char * given_string = &...
1
vote
2answers
29 views

Valgrind issue on PSET5 - Edited

sorry that this is a repost of a deleted question. I made a mistake in reading the specifications and didn't realise I wasn't able to alter the function declarations in dictionary.c & .h. The ...
0
votes
1answer
16 views

Why doesn't my code give me an output?

So I am very new to CS and I have been working hard twisting this code around in my mind trying to figure out why nothing happens when I run the program. It compiles fine, but whenever I put in any ...
0
votes
0answers
20 views

Recover Assignment Memory Leak and Insufficient Recovery

I am trying to complete the assignment given by CS50x (Harvard Community Online, edX.org), and while it successfully recovers images, valgrind is telling me that there are memory leaks that happen in ...
0
votes
1answer
20 views

incompatible pointer types passing 'string' (aka 'char *') to parameter of type 'string *' (aka 'char **')

Im writing a funtion that takes string as a argument and gives back a integer. This function counts lenght of a string entered at the command line argument. I get an error :" incompatible pointer ...
0
votes
1answer
19 views

Pset1 Creating and Changing Directory Does Nothing

For the first problem set, I attempted to create and change the directory with the following commands: $ mkdir ~/pset1 $ cd ~/pset1 $ mkdir ~/pset1/hello $ cd ~/pset1/hello Despite doing these ...
0
votes
0answers
51 views

CS50 - PSET2 - Substitution Segmentation fault

I keep getting 'Segmentation fault' every time I run the code(mentioned below). The code is compiling just fine. It's asking for input and is returning required message when the command line argument ...
0
votes
0answers
15 views

Why do I have a segmentation fault in my Caesar coding from pset2?

#include <stdio.h> #include <math.h> #include <cs50.h> #include <ctype.h> #include <string.h> #include <stdlib.h> int main(int argc, string argv[]) { if (argc != 2)...
0
votes
1answer
21 views

CASH issue - help needed

I've been struggling with this for a month now so any help will be appreciated. The program just returns the value of input, so although there are no errors in compiling, it doesnt actually produce ...
0
votes
1answer
41 views

Need help with CS50's Filter (less) Blur

I'm doing CS50 and trying really hard to keep sane while I try to finish the last part of the Filter (less) exercise. I'm stuck on "Blur". I've tried to resist looking for help online ...
0
votes
1answer
35 views

How can I get the cs50.h to run in Visual Studio Code?

I downloaded both the cs50.c and cs50.h files from GitHub and put them in the folder where all the header files are. VSC even recognizes the #include <cs50.h> in the code but I get the error in ...
0
votes
1answer
17 views

Is there an operator for raising in a power in C?

In PSET4 Edges Filter problem you are supposed to calculate Gx ^ 2. But the operator ^ in C does not seem to mean raising in a power. For Gx = -9 it returns Gx ^ 2 = -11 and so on. Turned out ^ is XOR ...
0
votes
1answer
21 views

dictionary is allways null

// Implements a dictionary's functionality #include <stdbool.h> #include <string.h> #include <stdio.h> #include <ctype.h> #include "dictionary.h" // Represents a ...
0
votes
1answer
33 views

My 'pset1 Mario more comfortable' is returning check50 errors whilst seemingly correct

I saw this question has been asked in multiple ways before but I believe I've checked answers and am still stumped as to the issue I have. The output for my pset1 Mario more comfortable appears to be ...
0
votes
1answer
53 views

PSET 1 Less comfortable Mario

I have been writing this code for a day but I still could not get the result I want, I don't even know how the is giving me a weird result. Here's my code: #include <cs50.h> #include <stdio....
0
votes
1answer
44 views

PSET5 speller memory leak and dictionary not unloaded

I have been looking at this for about 5 days now and I can´t find where I am leaking memory or if I have any problems with my code logic. Everything compiles and Valgrind output is below. I am ...
0
votes
1answer
37 views

Pset5 memory leaks

so I've been working on that speller code recently. It's actually working good, but valgrind returns memory leaks.. I do "understand" the problem of the first leak, but can't find a solution. Same ...
1
vote
1answer
41 views

Check function (pset5, speller) gives multiple, incorrect outputs for some reason

I've completed most parts of speller, but for some reason, when I try to test the check function by printing a 0 for every time it is supposed to return true and printing 1 whenever it should return ...
0
votes
0answers
16 views

Final Project C Makefile

For my final project for CS50, I'm designing a command-line C program but I'm having issues with compiling the program to test before submitting. I'm using three separate c files to store all my code (...
0
votes
1answer
19 views

Pointer passed as argument, then suddenly goes null

In the main method I declare a character pointer pCharacter. I pass this variable to the setCharacter method and assign it an address and a variable gets assigned to that address. From what I ...
0
votes
2answers
45 views

PSET5 Speller - Memory error

This has by far been the most rage-inducing pset in the course. Down to my last check50 error now, failing the "program is free of memory errors" test. I've run it in Valgrind and it says there are ...
0
votes
1answer
14 views

Syntax Highlighting Error

I am working on my mario problem. I write my code in C, but it's not getting highlighted, meaning the program doesn't understand it. How can I get it to understand my code? for example #include is in ...
0
votes
1answer
43 views

PSET5 Speller - Just totally lost, code compiles but all check50 tests fail

I've been beating my head against a wall on this pset for 10 days now, watched all the videos, solved all the compiler errors, and just when I felt like I kind of understood this thing I ran the test ...
0
votes
2answers
50 views

Do - While loop

I am trying to do the Mario problem with C. The issue is that I want the user to select a number from 1 to 8. So my boolean expression is (n < 9 && n > 0). But I don't know why is not ...
0
votes
1answer
21 views

Pset2 Caesar Memory Leak

I can't detect where I am leaking memory. Sometimes I get an unexpected output at the end of my array for cypher text and can't pass all test cases :(. Can someone point to me where I am wrong? Can ...
0
votes
2answers
22 views

error: result of comparison of constant with boolean expression is always true

So, I want to make a do-while loop, repeating the question for an input, so check if the input is in a range between 340000000000000 or 379999999999999 and my code is generating a compilation error: ...
0
votes
1answer
11 views

Split double digits into 2 seperate integers

i'm currently trying to do credit.c in pset 1, and I've managed to get every other digit separated and multiplied by 2, then added together, the problem is the next step "Now let’s add those products’ ...
0
votes
1answer
52 views

PSET 4 Recover - Only recovering part of the photo?

My program to recover JPGs runs and creates the files, but was failing check50. So I ran the debugger, and it looks like it's only recovering a small portion of each JPG. Not sure what I'm doing ...
0
votes
1answer
64 views

Recover function in pset4

#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <stdbool.h> /* Open memory card Repeat until end of card: Read 512 bytes of data into buffer If ...
0
votes
1answer
8 views

Splitting integers into seperate digits in C

i started to learn C a few days ago through the cs50 course and i'm trying to write a program as a side project where the user inputs a multi-digit integer, and the program will break it apart into ...
0
votes
1answer
32 views

CS50 PSet 4 Recover, Segmentation Fault

My code compiles, but whenever I run Check50, I get a segmentation fault error for each category. Would definitely appreciate any help identifying where the problem can be fixed! #include <stdio.h&...
0
votes
1answer
74 views

pset2 substitution

I was trying to do substitiution on two loops but i had some issues. i found onle loop solution here https://stackoverflow.com/questions/61767483/free-invalid-pointer-aborted-core-dumped-cs50 but now ...
0
votes
1answer
45 views

PSET4 Recover - Can't Read Card

Having a problem with Recover. The debugger shows that "buffer" is always 0000. Tried everything I could think of here. Any ideas? #include <stdio.h> #include <stdlib.h> #include <...
1
vote
2answers
50 views

passing argument 1 of ‘strlen’ from incompatible pointer type

How to make this working? How to properly find the length of these 8 listings? Whenever I execute it gives me following error. *passing argument 1 of ‘strlen’ from incompatible pointer type * #...
0
votes
2answers
98 views

CS50 pset3 plurality program gives error for print_winner function (did not print both winners of election)

I have finished the plurality program for pset3 of cs50, but upon running check50 on my code, I receive the following error directed towards the print_winner function: :) plurality.c exists :) ...
0
votes
1answer
38 views

Pset3 Runoff - Printing All Candidates

Could use some help with Runoff. If I do a simple clear winner (all voters vote for the same person as first choice) it prints out the winner just fine. But if I do the test input that the problem ...
0
votes
1answer
19 views

What's in the bool function parenthesis?

hope everyone is staying safe. I just want to understand what's inside the parenthesis of the vote function in pset3 - Tideman: bool vote(int rank, string name, int ranks[]) What does it mean to ...
0
votes
0answers
46 views

I am having trouble with the 2020 pset4 Recover assignment and even though my code compiles, it doesnt work, its not recovering the images

EDIT: I posted this 17 days ago please help. Heres my code and it wud be great if someone cud help A.S.A.P. thankyou! #include <stdio.h> #include <stdlib.h> #include<stdint.h> #...
0
votes
1answer
47 views

PSET 3 Plurality - Program works but also returns invalid vote?

For those who don't know, this pset is for calculating votes in an election. We were told to code the two functions vote and print_winner, and not to touch any of the other code. The program seems ...
0
votes
1answer
31 views

pset3 runoff print_winner check50 error

So I have seen this issue mentioned here before and the others have suggested that printing a newline after the name is the solution. However, my code does print a newline and in my tests, I'm getting ...
0
votes
1answer
63 views

CS50x Problem Set 4 Blur Function Issue. Does not work on 3x3 or 4x4 image

For some reason, my CS50 pset4 blur function is not returning the proper pixel values for a 3x3 or a 4x4 image. It passes the other check50 tests. I looked at the check50 output, and my code gets the ...
0
votes
2answers
50 views

When printing mario problem the second triangle appears below the first one

#include <stdio.h> #include <cs50.h> int main(void) { //This do while loop checks if user entered number 1-8 int x; do { x = get_int("Height: "); } while ...
0
votes
0answers
25 views

PSET4/filter: Help me see/understand RGB values of individuals pixels in BMP files

Before working on filters in problem set 4, I wanted to make sure I understood the basics. I have downloaded yard.bmp (attached here) and am trying to do simple operations (e.g. use pointers, extract ...
0
votes
2answers
101 views

Caesar doesnt pass “non-numeric key” check

I've read all the other answers I can find about people having a similar problem, but mine doesn't seem to be the same issue. Everyone says to use isdigit first, then use atoi, which is what I've ...
0
votes
1answer
46 views

My code for Caesar gets segmentation error when executed, but in debugger it works fine

I'm getting a segmentation error as soon as I execute this program. I've run it through the debugger and it works fine and outputs the correct ciphertext. There's gotta be something going on in the ...
0
votes
1answer
23 views

Confusion about comparing strings and int/char

This question concerns variables, pointers and addresses as addressed in Lecture 4. I understand that strings are not "real" in the way that integers and characters are, and are just defined as "...
0
votes
1answer
34 views

CS50 Tideman sort_pairs does not work correctly

I have checked my code with a few example and all of them returned the right answer. But when using check50, it tells me that my sort_pairs does not work correctly. Please help me :)! #include <...

1
2 3 4 5
10