Questions tagged [c]
The c tag has no usage guidance.
674
questions
0
votes
1
answer
8
views
Lab 1 - Terminal goes blank after I input end size
The terminal goes blank after I input end size. What am I doing wrong?
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// TODO: Prompt for start size
int start;
do
{
...
0
votes
1
answer
14
views
PSET3 Plurality - void print_winner(void) function
I am having a lot of difficulty with conceptualizing this function and applying this weeks lessons on algorithms. With the code below, what I have been trying to do is to mimic a selection sort, ...
0
votes
1
answer
7
views
Convert comma to point in a Float (C)
I wrote a code that I'm studying where the idea would be to show the change for a certain purchase, however, in the field where the customer enters the price, if I enter, for example: 9,50 instead of ...
0
votes
1
answer
7
views
Lab 5 - Inheritance check50 error
Attempted CS50 Lab 5 inheritance. My code looks correct and compiles. I also double-checked with Brian's solution and they were identical. Yet when I passed it through check50, I got multiple errors ...
0
votes
2
answers
8
views
can anyone help error check my luhns algorithm code?
i wrote this version of the credit card number checking code and it still gives me an error when i check it.
apparently, it validates 4111111111111113 and 4222222222223 as visa numbers when theyre not....
0
votes
1
answer
4
views
p is assigned a memory first but when create family is called again, isnt the last memory lost as now p points at a new chunk of memory?
person *p = malloc(sizeof(person));
// If there are still generations left to create
if (generations > 1)
{
// Create two new parents for current person by recursively calling create_family
...
0
votes
1
answer
14
views
Incorrect blur for filtermore
for this problem, I have opted to use a strategy where I create a 1 pixel border in a copy image with RBG values = 0, to avoid running into segmentation errors when trying to access a pixel. I also ...
0
votes
1
answer
17
views
PSET2 Caesar help - Rotate function
I have been getting the error message "expected identifier" for line 65 of my code pointing to the isupper function below. I can't see what I am doing wrong and any help would be appreciated ...
0
votes
1
answer
30
views
HELP! Speller segfault
my speller code compiles but it gets segfault.
I'm not sure where I went wrong, my guess is load but I'm not sure.
#include <ctype.h>
#include <stdbool.h>
#include <strings.h>
#...
0
votes
1
answer
21
views
filter-less blur function
I am stuck at pset4 filer-less, blur function. The duck and chatgpt say that my code is correct but it doesn't give excepted outputs in any of Check50 result for blur function.
//Blur image
void blur(...
0
votes
1
answer
19
views
Issues with readability functions
I am having difficulty getting past creating the first function of my code, line 61. I have tried many different variations and I suspect that I am just not understanding a basic concept of the ...
0
votes
1
answer
33
views
Credit : the checksum is correct for <10 digits, but for14,15,16 digits getting negative checksum
The checksum is correct for less than 10 digits but for 14-16 digits it is coming back negative. What am I doing wrong?
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int ...
0
votes
2
answers
35
views
pset4 blur; artifacts on a white parts of an image
I believe I've done this part of filter-more task pretty well, but, unfortunately, an output image has some artifacts - blur works badly with white parts of an image.
void blur(int height, int width, ...
0
votes
0
answers
14
views
How to add a file to a directory(in this case, a "dictionary.txt" file)
I am trying to add a dictionary.txt file to my program in order to get a randomly generated five-letter word, however, it keeps saying there is no such file or directory, how should I fix this problem?...
0
votes
1
answer
11
views
runoff is_tie and print_winner
I'm having a hard time seeing where I went wrong with my two functions IS_TIE and PRINT_WINNER
when I put my code through check50, for print_winner I get: "did not print winner of election" ...
0
votes
1
answer
14
views
The code doesn't give me correct decimal answers
The code doesn't give me the right decimal answers after calculating, and it also doesn't prompt the user to re enter the right value when it's less than 9,as I expected. I'm new in programming, can I ...
1
vote
1
answer
21
views
Practice Problem 4: error: incompatible pointer types passing 'char *[7]' to parameter of type 'char *' [-Werror,-Wincompatible-pointer-types]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
// Check for command line args
if (argc != 2)
{
printf("Usage: ...
0
votes
1
answer
34
views
pset 5 speller do not pass check 50
I do not know what I am doing wrong. Please, give me a hint.
Here is my solution from check50:
:( spell-checking is case-insensitive
Cause
expected "MISSPELLED WOR...", not "MISSPELLED ...
-1
votes
1
answer
29
views
error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char*'...printf (y)
I've been trying to run this code,but it shows an error message.I'm new in proramming.Can I please get help on what to do.
#include <cs50.h>
#include <stdio.h>
int main (void)
{
int i ...
0
votes
0
answers
38
views
reverse isn't properly reversing the file
The audio file that is generated not reversing the audio correctly. Here is the code:
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "wav.h"
int ...
0
votes
1
answer
45
views
pset5 speller cannot read number of word in dictionary
thank you for clicking. Being concise, I have the right solution for the pset, as evidenced down below by comparing my solution to the staff's, but check50 insists that no words have been loaded into ...
0
votes
1
answer
32
views
Pset4- recover: recovered jpgs appear to be empty
I tried to implement recover through the simplest and shortest way I could imagine.
The code compiles and saves 50 JPGs with proper names, but when I open them, all of them are just empty and even ls -...
0
votes
1
answer
29
views
Pset5 Speller - Weird Load Function Bug (Edited w/ Code)
bool load(const char *dictionary)
{
// TODO
FILE *fdict = fopen(dictionary, "r");
if (fdict == NULL)
{
return false;
}
// create container string to hold ...
0
votes
2
answers
40
views
CHECK50 Passes, but I Get 6/7 When Submitting
I've just completed pset4 - recover.
I did quite a bit of debugging and was finally able to pass all checkmarks with check50, style50 and Valgrind. After submitting I checked my grade and I received 6/...
0
votes
2
answers
67
views
cs50 license memory free
Was trying to free memory using the for loop,
for (int i = 0; i < sizeof(buffer); i++)
{
free(p[i]);
}
but got this error
license.c:46:14: error: incompatible integer to pointer ...
0
votes
1
answer
31
views
Recover PSET 4 Week 4 - skipping while loop
This is a follow up to my previous question. After I went through my code on debug50 it shows that my while on line 35 is not going through. I checked my code with other others on this site and they ...
-1
votes
1
answer
33
views
CS50 PSET 4 Recover - segmentation fault and blank file
I have been trying to solve this question for a while now but I am still not sure what is wrong. The program works fine before the while loop but after it stops working and when checking with check50 ...
0
votes
1
answer
25
views
How to merge sort array of struct while maintaining relations between int array and char array
Does anyone know how I could maintain relations between the char and int in structs while merge sorting the ints in the struct? So if I had nameandnumber[1].buffer assigned a value that used to be at ...
0
votes
2
answers
26
views
Problem set 2 , Passes all tests when submitted but only give 2/11 grade
check50 results in all the tests passing but also produces a repetitive error, Invalid key. Please provide a positive integer. Cause Timed out while waiting for program to exit. Not sure which line ...
0
votes
1
answer
25
views
hey im on pset2 readability. i cant seem to get the right output. it is supposed to show letters= and words= but its not
#include <stdio.h>
#include <cs50.h>
#include <string.h>
int count_letters(string text);
int count_words(string text);
int count_sentences(string text);
int main(void)
{
// Get ...
0
votes
1
answer
32
views
Problem with my code (Problem Set 1 - Credit)
#include <cs50.h>
#include <stdio.h>
int checksum(long n);
int main(void)
{
long card_number;
int k;
// Prompt user for card number
do
{
card_number = ...
0
votes
2
answers
20
views
psets2/scrabble.c, In pset2, scrabble im running into an error incompatible comparison between type int and char
How does [POINTS[word[i]] work, I don't seem to get it, somehow I got it to work, but many times it is showing incompatible comparison between type int and char.
0
votes
1
answer
13
views
Code for pset5 compiles, but produces no OUTPUT. Seems like it is stuck in infinite loop
Description of Problem:
Hey guys, so my code is outputting only MISSPELLED WORDS and then it apparently gets stuck in an infinite loop. So that I have to type ctrl + C to be able to type anything in ...
0
votes
1
answer
24
views
Speller works fine up until a certain point
My speller program has an issue where it will find what words are misspelled properly, but it won't give the data of the amount of words misspelled/ in the dictionary/ in text. Running Check50 shows ...
-1
votes
1
answer
47
views
CS50 Pset 4 edges: Why do I keep getting segmentation fault?
Please help me figure out what's wrong! I've been doing this pset for so long now, and I feel like everthing should work, But I just get a seg fault! The code looks like...
void edges(int height, int ...
0
votes
1
answer
49
views
make: *** No rule to make target 'hello'. Stop
I recently started the cs50 2023 course, and from the beginning I faced problems
When I type "hello world" code, I get this error
make: *** No rule to make target 'hello'. Stop
What is the ...
-1
votes
1
answer
109
views
recursive atoi | CS50
Greeting everyone! I've written the code of pset3 recursive atoi, but I'm facing an issue with the formula that converts the integer to its place value. To be specific it's in this line (number = ...
0
votes
2
answers
48
views
Stuck on Lab 1 #CS50
I'd appreciate your help as I'm stuck on the last part of Lab 1.
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// TODO: Prompt for start size
int start;
do
{
...
0
votes
1
answer
25
views
Stuck in mario-less directory in terminal CS50
I am working on cs50 mario less but im having trouble getting into the file mario.c In terminal I follow the steps to setting up the files and have no problem getting into the mario-less directory.
...
0
votes
1
answer
20
views
For Loop to look through all values of an Array
So, I am learning C using cs50 and a problem I have run into is that although i have yet to learn about arrays, I need to use arrays for my problem set. I would really appreciate it if someone could ...
0
votes
0
answers
9
views
For CS50 plurality, check50 says that my code doesn't print the winner of the function. But it does?
#include <cs50.h>
#include <stdio.h>
#include <string.h>
// Max number of candidates
#define MAX 9
// Candidates have name and vote count
typedef struct
{
string name;
int ...
0
votes
1
answer
23
views
How to Solve : expected identifier or '('
here is my code:
#include <stdio.h>
#include <cs50.h>
//Declaring User-Defined Functions
int last_digit(int sum3);
int main(void)
{
//Promting the user for credit card number
...
1
vote
2
answers
76
views
variable used in loop condition not modifies in loop body
im struggling with pset1 cash exercise, when im defining a calculate_quarters() and other in the same way i got an error. the task is to find out the number of quarters, dimes, nickels and pennies to ...
2
votes
1
answer
319
views
What's the most efficient prime-finding algorithm? (Week 1 Practice Problems)
In the Prime practice problem, there's a thought question that says:
Can you make the prime-finding algorithm more efficient than checking
if a number is divisible by every number between 2 and 1 ...
0
votes
0
answers
16
views
CS50 Filter - less, sepia function not giving output as expected
What did i do wrong here, I'm on blur function right and i compiled my code and it compiles gives sepia filter but with bit of green bleed on 3 out of 4 pictures i went through my code but cannot find ...
0
votes
0
answers
20
views
Problem of pset3 plurality
This code can run, but the outcome isn't right.I checked many times, but I still can't figure it out.I wish someone can help me.
Here is the function "print_winner" of my code:(I guess the ...
0
votes
1
answer
39
views
PSet5 Speller: Are we hashing the words in the dictionary into a hash table or the words of the text?
I've completed the first function of the Problem set, where I've sorted every word in the dictionary into a trie, but I don't know if I was supposed to do that in the hash function, and something else ...
0
votes
1
answer
16
views
PSet5 Speller: What is each function in dictionary.c supposed to do? [closed]
I've started working on this PSet, and now I'm confused because in the instructions I can't figure out where it tells me what each function is supposed to do. Hash is never even called in speller.c so ...
1
vote
1
answer
15
views
PSet 4 - Recover. The first picture (000.jpg) doesn't get recovered, all other images do (049.jpg is the last image recovered)
Everything else works in my code, no memory leaks, all other images are loaded properly, except the first one. I've gone through debug50 to try and see the problem, but I can't seem to find one since ...
0
votes
1
answer
21
views
cs50 pset5 not enough memory
I have been stuck here for several days. After loading 52209 words, I keep encountering Segmentation fault (core dumped). I think that I am consuming memory unnecessarily somewhere in the code, but I ...