Skip to main content

Questions tagged [c]

The tag has no usage guidance.

168 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2 votes
0 answers
790 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 ...
gargi's user avatar
  • 23
2 votes
1 answer
1k views

C Preprocessor Output: What is <built-in>

I wrote one of the most simple programs I could imagine: int main (void) { int a; } As you can see, there are no include files. The purpose is to understand a little bit more about the ...
Jonathan Soifer's user avatar
1 vote
1 answer
13 views

pset1 cash compiles but gives unexpected outputs

I'm having trouble figuring out why I'm getting the outputs that I am. I tried to write a function that I can re-use for each denomination of coin, not sure if the problem is there or somewhere else. ...
if_indeed's user avatar
1 vote
1 answer
51 views

PSET 2 Caesar : help part 3 : ciphertext rotating correctly but not printing out

*Edited to include the latest changes in the code. Can someone help me spot the problem with my code? Below are the results from check50 and the code itself. TIA!! Here is the prior question: PSET 2 ...
AmyG's user avatar
  • 41
1 vote
0 answers
1k views

pset2 - Bulbs - reversing array turns out wrong

I managed to make the right sequence of binary code (in reverse). Next, I do a for loop for reversing it, but it prints out wrong. I have no idea what happens, as the original array is correct, ...
yogmel's user avatar
  • 11
1 vote
0 answers
103 views

Lab 4 not altering output file - using solution word for word

I have looked at all the solutions here on the exchange. I have two issues. Firstly: const int HEADER_SIZE = 44; This does not work for me in the context of initializing a header array. I either have ...
madmonkey's user avatar
1 vote
3 answers
9k views

Why am I getting an “invalid slug” message when running check50

I am trying to complete problem set 2 for cs50 and I am having trouble fixing my program , can anyone tell me why? #include <stdio.h> #include <cs50.h> #include <string.h> #include &...
Jay MiNZ 's user avatar
1 vote
2 answers
4k 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 * #...
Khas Tricks's user avatar
1 vote
0 answers
63 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 ...
Elena Kalema's user avatar
1 vote
1 answer
145 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? ...
Ryked's user avatar
  • 11
1 vote
1 answer
318 views

pset2 vigenere; isalpha is accepting numbers in argv[1]

I'm using the construct if(isalpha(argv[1][i]) == 0) to determine if the chars are alphabetical in argv[1] with a for loop. The program compiles, however, isalpha does not appear to be working. If I ...
Iury Sikorsky's user avatar
1 vote
0 answers
2k views

Valgrind says "Invalid read of size 4" while freeing memory recursively in a trie

My PSET "mispelling" works fine and contains no memory leak but when I run the program with Valgrind it says Invalid read of size 4. My unload function calls a deleteTrie function which looks like ...
Milan's user avatar
  • 55
0 votes
0 answers
7 views

stuck on pset 4 filter : blur

// Blur image void blur(int height, int width, RGBTRIPLE image[height][width]) { RGBTRIPLE copy[height][width]; float Sum_Blue = 0, Sum_Green = 0, Sum_Red = 0, surrounding_pixels = 0; for ...
Rishav Jain's user avatar
0 votes
0 answers
9 views

debug50 not working

I was working on a project in C. When I tried to use debug50, the command failed bash: debug50: command not found I am using the usual command: debug50 ./{program-name} I have already restarted the ...
wanttocode's user avatar
0 votes
0 answers
22 views

Pset4: Check50 is not compiling my code for Filter-More

I tested my code and all functions seem to be working fine, I don't know what else to do. This is the output from check50, there are no warnings or hints about what I might be doing wrong. https://...
gabi's user avatar
  • 1
0 votes
0 answers
15 views

Tideman: Is my thinking correct for sort_pairs and lock_pairs?

I have just finished tideman and passed all checks on check50. However, I wanted to check if my thinking for my code is on the right track, or I got here just by luck. Firstly, for sort pairs, this is ...
Seanie's user avatar
  • 1
0 votes
1 answer
20 views

Can someone help me understand why we multiply the quarters by 25

// Subtract the value of those quarters from cents cents = cents - (quarters * 25);
Victoria's user avatar
0 votes
0 answers
35 views

problem with speller problem set 5 code

well i have a problem with speller problem set 5 code. For some reason check50 returns everything wrong but when i debug it seems fine. I don't really know what the problem with my code is. This is my ...
dhan8293's user avatar
0 votes
1 answer
17 views

Problem set 2, substitution -> I don't get why check50 shows that my output is incorrect

#include <cs50.h> #include <ctype.h> #include <math.h> #include <stdio.h> #include <string.h> string cipherText(string key, string text); bool checkKey(string key); int ...
NawafBRQ's user avatar
0 votes
0 answers
19 views

My cs50 prset2 caesar project rfused to compile,

My cs50 pset2 caesar project refused to compile, what could be the problem. Says can't run until frown turn upside down.
Donald Udofia's user avatar
0 votes
1 answer
21 views

How to get value of variable after a loop

Here is my code to count the sum of 5 and 1 coin of a certain money to be the less. But I have to assign variable c to variable v because if not do so, the program will stop if the money is less than ...
binhsuy's user avatar
0 votes
1 answer
55 views

Pset 2 Caesar: Problems with argv[] as a parameter

I have two main questions for my code. Please excuse me for my tideous code and for not using existing functions in the library, i.e. isdigit and strlen, as I didn't want to become dependent on them ...
pinkmonster's user avatar
0 votes
1 answer
117 views

Valgrind output of Speller task. (debuginfo reader: Possibly corrupted debuginfo file)

I've just completed Speller task. When I run the task with valgrind on command line I encounter some kind of error, which I don't know how to deal with. I'm going to attach the error image and ...
Shahin Karimli's user avatar
0 votes
0 answers
206 views

Line 32: Char 5: error: redefinition of ‘main’ [solution.c] 35 | int main(int argc, char *argv[]) { | ^~~~.Why this is showing in my C program

#include<stdio.h> #include<ctype.h> int main() { int nums[] = {1,3,4,5,6}; int i, j, x=10, n; printf("target="); scanf("%d",&n); int size =...
Shimul Das's user avatar
0 votes
1 answer
11 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 { ...
rushil_01's user avatar
0 votes
1 answer
30 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 ...
Jarret's user avatar
  • 1
0 votes
2 answers
16 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....
sam's user avatar
  • 1
0 votes
1 answer
6 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 ...
Omer Matin's user avatar
0 votes
1 answer
27 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 ...
Kik's user avatar
  • 1
0 votes
0 answers
16 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?...
Dragan Cvetkovic's user avatar
0 votes
0 answers
44 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 ...
Splendid Digital Solutions's user avatar
0 votes
1 answer
18 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 ...
Mateus Machado's user avatar
0 votes
1 answer
33 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 ...
esqflowne's user avatar
0 votes
1 answer
147 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 ...
bop's user avatar
  • 1
0 votes
2 answers
62 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 { ...
Kareem's user avatar
  • 1
0 votes
1 answer
27 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 ...
molearns's user avatar
0 votes
0 answers
15 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 ...
Harrison 's user avatar
0 votes
0 answers
27 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 ...
Sandesh Prabhu's user avatar
0 votes
1 answer
40 views

My pset1 (cash) code compiles but the outputs are wrongs. Could you Help me?

This is the code: #include <cs50.h> #include <stdio.h> int get_cents(void); int calculate_quarters(int cents); int calculate_dimes(int cents); int calculate_nickels(int cents); int ...
Santiago Misas's user avatar
0 votes
1 answer
47 views

cs50x Pset5 Speller has a memory leak that I can't find

I am currently taking CS50x and am on Pset5: Speller. My code works as intended, however when I run the check50 function my program fails Valgrind. This is particularly confusing to me because when I ...
Zach Anderson's user avatar
0 votes
1 answer
793 views

comparison between pointer and integer ('const char' and 'char')

I'm not familiar with C, not sure what this error means.. could anyone help? #include <ctype.h> #include <cs50.h> #include <stdio.h> #include <string.h> // Points assigned to ...
matt.mcg's user avatar
  • 101
0 votes
2 answers
17 views

Getting segmenatation fault even though i freed memory

#include <stdio.h> #include <stdlib.h> #include <stdint.h> typedef uint8_t BYTE; int main(int argc, char *argv[]) { // Only allow 2 command line arguments if (argc != 2) ...
lukadeving's user avatar
0 votes
2 answers
380 views

cs50 error - Linker command failed with Exit code 1

I've been trying to do one of the sample programs in lecture 1 and keep being prompted with the same error. However, when running a simple "Hello, world" program it executes fine. I've ...
Gabriel Tierra's user avatar
0 votes
0 answers
18 views

How do I take imported user strings from an array and print a random one out in C?

// Helps a user decide which homework to do first #include <cs50.h> #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { // Prompt the user for the ...
Tyler's user avatar
  • 1
0 votes
1 answer
5 views

Looking for a way to make a loop that rejects an input with any other hour format other than the one specified

Im having trouble creating a code on C that after letting the user input a date it determines if the date is in a valid 24 hour format, any help would be greatly appreciated. Here's my code. #include &...
Jorhan López's user avatar
0 votes
0 answers
75 views

CS50-C compiler doesn't working

I can't run the code on cs50 C section is there something wrong with my compiler
user14288642's user avatar
0 votes
0 answers
19 views

edges(pset4) i need feedback and help on my code?

can anyone suggest anything to fix my code cause all i get for output is a black screen. im doing cs50 problem set 4 and im stuck on edges filter. RGBTRIPLE copy[height][width]; copy[height][width] = ...
Alex M's user avatar
  • 1
0 votes
1 answer
156 views

How do I return my array of chars in a function to a string in main()

I'm having difficulty implementing the two sections of code for the caesar pset. Individually I have made both my main() and my rotating algorithm caesar() work, but am having trouble combining them, ...
krexaim's user avatar
0 votes
1 answer
175 views

Undefined reference to main, why? (C)

getting undefined reference to main but not sure why. The code is the same as the guy in the lecture but it seems to not work while his does? im very new, and very stupid..
David Harris's user avatar
0 votes
1 answer
82 views

Function returns not working for CS50 readability.c

In CS50 we now have to make multiple functions (I guess they want us to get used to objective-oriented programming for the python part later) and return the value to the main function. When I execute ...
Max Grossenbacher's user avatar