Questions tagged [c]

The tag has no usage guidance.

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

pset4 Blur calculation does not work properly

for some reason I can't get my calculation for the blur value running. The pictures are really odd and contain crazy colors. Any ideas to why this could be the case? I compared it already to working ...
0
votes
1answer
14 views

Mario less, struggling with nested FOR loop

hello I have got my code to work but don't understand logic, I found a flow cart for how nested for loops work and with that I was able to mix things around until I got it to output correctly but ...
0
votes
1answer
14 views

How can i arrange the output in decending order In this program?

#include <stdio.h> int main() { int n,i; printf("Enter a number: "); scanf("%d",&n); for (i=0; i<=n; ++i) { if (i%(7*13*19)==0) { ...
0
votes
1answer
15 views

Why is my get_positive_int code not working? (I seem to do everything right!)

Here's my code (written in C), I was trying to program this for a long time, and even when I just tried to copy the code directly from the video lecture, it's wrong! Please help me. Here's my code: #...
0
votes
1answer
6 views

Caesar - ASCII to char conversion problem

Going through the CS50 exercise Caesar, and I'm still very new to C. My code to validate the key is all working, but as I try to convert from plaintext to the cipher text I keep getting caught up with ...
0
votes
1answer
16 views

pset4 recover creates 50 images but bytes don't match up

My code creates the 50 files, all of them starting with the correct JPEG signature, however the rest of the bytes don't match up. In other words, first 4 bytes are correct, the following bytes are ...
0
votes
0answers
7 views

Pset4_ Blur: (more comfortable)Problem, I think there is a small bug, but I can't find it

I was working on my code(sorry for it being so long), then I kept getting the same error and I don't understand why :) blur correctly filters middle pixel :) blur correctly filters pixel on edge :) ...
0
votes
1answer
25 views

Pset3 Tideman: Why is my sort_pairs function not working?

I'm green on all the criteria before sort_pair. Here's my code so far: // Sort pairs in decreasing order by strength of victory void sort_pairs(void) { // TODO // Create array of strengths of ...
-1
votes
2answers
20 views

while (n<1) --— Why?

Week 1 - mario exercice. Into the program below , I do not understand why while (n<1) As width is a positive value, n shouldn't be >1 ? -----------------------------------------------------------...
0
votes
1answer
16 views

String to Char in C

How can I convert a String to a Char in C? Please help. I am unable to do that and I need it urgently. I need it for readability.
0
votes
0answers
19 views

Help, doe not working - cash [duplicate]

Can someone please help me, as much as I think it should give the least amount of coins needed but it is not.
0
votes
1answer
32 views

Code not working - cash

Can someone please help me, as far as I think this code should give back the number of coins needed but it is not working.
0
votes
1answer
14 views

Seg fault (storing file pointer as NULL initially maybe?)

// img file pointer FILE* img = NULL; char* file_name = NULL; int file_count = 0; int bytes_written = 512; // repeat until end of memory card while (bytes_written == 512) // ...
0
votes
2answers
33 views

Blur look correct but check50 says its not?

See my check50 results here // Blur image void blur(int height, int width, RGBTRIPLE image[height][width]) { RGBTRIPLE tmp_image[height][width]; for (int y = 0; y < height; y++) ...
0
votes
1answer
14 views

reflect for cs50. Trying to reflect an image, but only the first row pixels is swaped

So, my task is to reflect image pixel by pixel to make a mirror image. Here is my original code for the function void reflect(int height, int width, RGBTRIPLE image[height][width]) { int tempr, tempg, ...
0
votes
1answer
18 views

how can I rewind the fread() funtion as byte

is there a way to fread() the same bytes you just had read? fread(buffer, 512, 1, inptr); if (header(buffer) == true) { //execute these lines do { //execute these lines } ...
0
votes
1answer
35 views

Pset 4 Filter(less) Blur

I'm having an issue with the counter variable of my code. I wrote a printf to see if it returns 4, 6, or 9. Which is what it should do, if my IF conditions are correct. Unfortunately it does not ...
0
votes
1answer
56 views

pset3 tideman lock_pairs: why does “lock_pairs locks all pairs when no cycles” fail?

My code fails at check50 but I can't understand why. It that seems my code actually finds cycles, but also produces false-positives (I guess). check50 output for the lock_pairs function: :( lock_pairs ...
0
votes
1answer
12 views

I finally got my code to work but now I can't submit it can anyone tell why?

tps://i.stack.imgur.com/SvfAI.png
0
votes
1answer
47 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
1answer
39 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
18 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
2answers
44 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
63 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
9 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
23 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
20 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
66 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
41 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
35 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
25 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
17 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
28 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
44 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
56 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
34 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
45 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
18 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
23 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
94 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
44 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
27 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
44 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
12 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
43 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 ...

1
2 3 4 5
11