Questions tagged [c]

The tag has no usage guidance.

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

pset1 credit: I am unable to identify what's wrong in the logic of my code?

Kindly tell me what mistake have I made in this program? pset1 Credit: (my code) https://pastebin.pl/view/5646dbf1
0
votes
0answers
14 views

pset3 tideman cs502020 locked pairs error

I am new to coding and I am trying to solve the locked pairs part of the Tideman problem. Currently, I am receiving the following two errors: :) lock_pairs locks all pairs when no cycles :( lock_pairs ...
0
votes
1answer
14 views

What is the purpose of subtracting 1 while inside a increment? [closed]

I am confused about the code below ++counts[number-1]; What is the purpose of subtracting 1 in this code? The entire code: #include <iostream> #include <iomanip> #include <ctime> #...
0
votes
0answers
14 views

floating point exception (core dumped) while using modulus operator [closed]

Here's the piece of problematic code: #include <stdio.h> #include <stdlib.h> int main(void) { int n = 0; int q = 0; int Z = 0; scanf("%i %i", &n, &q); fgetc(stdin); int ...
0
votes
1answer
26 views

Check50 all green but my own tests fail

I completed Runoff with 100% pass in check50 but when i do my own tests i get wrong winners. I checked everything to the best of my abilities but i just can't find the problem and it's driving me ...
0
votes
1answer
10 views

cs50 array initializer must be an initializer list

i have started coding in c but i keep getting errors i don,t know how to solve maybe it is because i am used to coding in php language but i hope anybody can help me #include <stdio.h> #include &...
0
votes
1answer
8 views

Strange CL output

I was testing my code to see if the command line argument's characters are digits but after plugging a random argument that was a mix of letters and numbers, I obtained a strange output. See what you ...
0
votes
1answer
13 views

Pset 2 - Readability -> Wrong grade

I'm having problems with the Pset 2 problem: readability. The goal of exercise is to implement a program that computes the approximate grade level needed to comprehend some text using the Coleman-Liau ...
0
votes
1answer
11 views

Error: function definition is not allow here What error is this?

main.c:10:24: error: function definition is not allowed here int read( int a[9][9]){ ^ main.c:36:24: error: function definition is not allowed here void show(int a[9][9]){ ^ main.c:58:24: error: ...
1
vote
2answers
38 views

pset2 - readability - grades slightly off

I have a problem that I have not been able to diagnose on my own or by perusing this stack overflow. The the tests are here. All of the index values are correct except for the grade seven sentence ...
0
votes
2answers
31 views

Segmentation fault error in pset5

I did the speller and had some errors that I solved, but now I'm stuck and need help. I debug the load and hash (I know it's not ideal, but it works:)) Now I'm receiving the Segmentation fault error ...
0
votes
1answer
24 views

cs50 speller code complies and run also successfully. but it not qualifying for big board

:) dictionary.c and dictionary.h exist :) speller compiles :( qualifies for Big Board expected exit code 0, not 139 :| passes benchmarking can't check until a frown turns upside down how to fix this *...
0
votes
0answers
22 views

cs50 pset3 tideman lock pairs and print winner function are not working rest all are working

in lock pair (lock_pairs skips final pair if it creates cycle is working) rest all lock_pair and print winner is not working. #include <cs50.h> #include <stdio.h> #include <string.h> ...
0
votes
0answers
4 views

Json header file for C

Is any header for json in C, form which we can parsh any json file of 2D, 3D , etc. or is any other way to work with json in C programming language. from which we can parsh our json data and get it ...
0
votes
1answer
16 views

this code generates wrong results

I have some issues with this code it just prints the very first part of the image right and the rest of it just a gray screen can anyone help please. #include <stdio.h> #include <stdlib.h> ...
0
votes
0answers
10 views

This code gives wrong results

#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> typedef uint8_t BYTE; int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: ./...
0
votes
0answers
24 views

tideman sort pairs not working

dont know why my function isn't working, i suspect the while loop triggers even when it shouldn't. void sort_pairs(void) { // TODO supair supairs[pair_count]; supair unSorted[pair_count]; ...
0
votes
1answer
34 views

Why check50 says my code is wrong?

I am doing the problem set 3 of CS50, called plurality. When I test my code, it gives me the right anwsers. In other words, it gives me the right winner of the election. If there are two or more ...
0
votes
1answer
23 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 &...
0
votes
1answer
13 views

What is there a number between % and i? What Does it mean?

I am trying to understand a program in c and there is a format which I do not understand. Below is what I do not understand %06i I do not understand why there is 06, why is it needed. Below is an ...
0
votes
1answer
33 views

pset4 - can't figure out what i'm doing wrong - recover

This is the code: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { if (argc != 2) { return 1; } FILE *file = fopen(argv[1], "r&...
0
votes
1answer
31 views

Having trouble with Cash but does not know what is wrong

I am having trouble with my code for pset1/cash. When I check the code, this is my output: :) cash.c exists :) cash.c compiles :( input of 0.41 yields output of 4' expected "4\n", not "...
0
votes
1answer
16 views

Struggling to understand file I/O

everyone. I'm just starting my journey in learning to code, starting with C. And for the past few months, I've been struggling to understand file I/O. More often than not, I don't get the output I'm ...
0
votes
0answers
22 views

Why does my program print 0 after printing everything else since I have not put a return statement on it for anything

when i run it then it prints everything out but it also prints out zero, when i put return 0; then it still displays zero. What could I be doing wrong?
0
votes
1answer
13 views

Implicit declaration of function of a declared prototype PSET4

I have this error code: helpers.c:56:13: warning: implicit declaration of function 'swap' is invalid in C99 [-Wimplicit-function-declaration] swap(height, width, image, i, j); ^ helpers.c:62:6: error:...
0
votes
1answer
29 views

How do I generate random numbers between two number and fill them in an array in c?

I am trying to write a program that generates 10 random numbers between two numbers and put them into an array in c but am having a hard time on how to do it.
0
votes
0answers
34 views

Problem Set 3 - Tideman Lock Pairs

I am trying to solve the tideman problem for pset3. I have managed to get all parts of my code working apart from the the two parts which relate to checking whether cycles are created. :( lock_pairs ...
0
votes
1answer
24 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
11 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
41 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
11 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
41 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
20 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
24 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
35 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
30 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
86 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
19 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
27 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
48 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 ...
1
vote
2answers
112 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
21 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
23 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
47 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
67 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
48 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
44 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
53 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
22 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 ...

1
2 3 4 5
11