Questions tagged [c]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
2answers
629 views

Update a value in the function

I want to update variables relating to velocities in a different function to where it is declared. But am not fully understanding the syntax for it. I have the prototype as follows: void moveBall(...
1
vote
1answer
199 views

How come we can use objects in a structured programming language like C?

I noticed that data types like GWindow, GOval, etc. are actually classes and we are declaring objects using those eg. GWindow window; and GOval circle;. Here window and circle are objects right? How ...
1
vote
2answers
343 views

Indentation Help

Is my code correctly indented? Please help. I'm not sure it is correctly indented according to the CS50 Standard.
1
vote
1answer
176 views

How to make variable's value display on screen using printf?

I tried printf(n, " is equal to " x, /n); But it didn't work. How do I make it print the value of n (a variable ), then a space after it then "is equal to " then the value of x.
1
vote
2answers
57 views

Reducing the size of my `filename` array produces strange behavior when using `sprintf()`

Why is it that if I reduce the size of the array in the code below from filename[4] to filename[3], the filename string is always 001? char filename[4]; // if i change 4 to 3, i get filename as 001 ...
1
vote
3answers
111 views

How do people usually look up syntax?

I've been doing problem set 1, and I seem to be running into blocks with syntax that I do not know, so I can come up with pseudocode and have a rough idea of what I want to do, but then when it comes ...
1
vote
1answer
564 views

where is the Debugger in Gedit for C

I have been having some trouble writing my programs. I have been trying to find the debugger for c to speed up the process, but I have not succeeded. If you have found it can you please tell me where ...
1
vote
1answer
17 views

Mario problem: Program got stuck at user input

// ** Below is the code of mario pset1, its taking input of width multiple times and not executing step after input// #include <cs50.h> #include <stdio.h> #include <math.h> int main(...
1
vote
1answer
29 views

'stadio.h' file not found

#include <stadio.h> int main(void) { printf("hello, world"); } when i type make hello clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-...
1
vote
1answer
46 views

Recover - segmentation fault and other general problems

Hey guys so I've hit a bit of a wall with Recover, when I run my program I get segmentation fault but I also don't know how to end off one jpeg when another header pops up? In essence, I'm not sure ...
1
vote
2answers
95 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 ...
1
vote
1answer
74 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
vote
1answer
399 views

PSET2 Substitution - Output seemingly correct, fails check50 (null character?)

thank you for your help in advance! I can't wrap my head around what's wrong with my code as the output is (seemingly) correct. I suspect it has something to do with the null character. #include <...
1
vote
1answer
760 views

CS50 - Filter - Reflect Image

I am working through CS50's PSET #4, specifically filter -> reflect. I can get the image to present correctly (i.e., it is mirrored), but it is not exact enough to pass the CS50 Check. My code is as ...
1
vote
2answers
237 views

getchar doesnt work as expected

for loop iterates only one time and chr only takes one value. #include <stdio.h> #include <ctype.h> //isalnum, ispunct, isalpha //#include <cs50.h> #include <stdlib.h> // ...
1
vote
1answer
438 views

Prompt for integer > 2 and < 8 in C

Really rookie question about C... I want the user to enter a number between 2 and 8, and if they don't, the prompt repeats itself until an integer within my parameters is entered. I can get this to ...
1
vote
2answers
57 views

Cs50 pset1 mario syntax errors or wrong code

Okay so I've tried multiple ways to get my blocks to simply create columns and rows first before adding spaces (though I've tried). I've watched and rewatched the lecture multiple times but I can't ...
1
vote
1answer
9k views

pset1 Error: indirection requires pointer operand

Here is a snippet of my code: long long card = get_long_long(); long long *FindLength = *card; long long *FindFirstTwoDigits = *card; And here are the errors: credit1.c:8:29: error: indirection ...
1
vote
1answer
43 views

Output of characters at specific place place using uint_list

I am trying to make an output using 3 characters (vertical line, plus sign, minus sign) and using uint_list to increase or reduce the length. #include <stdio.h> #include <stdlib.h> #...
1
vote
1answer
23 views

For loop in main function isn't executing

Blockquote #include<stdio.h> char a; int degree; void integration(); double *p; int i; int main(void){ //getting info from users printf("please enter your variable here:\n"); scanf(" %c"...
1
vote
1answer
767 views

Pset 4: Resize (more) -- check50 all correct except one

The code I have written for resize checks out visually for all float values (0.0,100.0]. Also, check50 agrees that my code is functioning properly save for one specific case: :) resize.c and bmp.h ...
1
vote
2answers
54 views

2 check50 errors to go

My program creates 50 jpegs run once no errors! ... Pseudocode: while fread buffer from card.raw while first 4 bytes is jpeg header // start of jpeg create filename fopen ...
1
vote
1answer
640 views

Pset1 (greedy) - How do i better design this program ?

Are there any tips and tricks i maybe can use to optimise this program, less declarations of variable, less lines, less loops ?; so i could invest effort later. #include <cs50.h> #include <...
1
vote
1answer
34 views

Pset1 Greedy, Can not get my logic correct

OK so I am stuck on greedy, I am trying to do small steps at a time and using my logic I thought I was right but seems I am incorrect about my formula. I start with the quarter section and only use ...
1
vote
1answer
91 views

Pset4 recover.c Still getting a Seg fault

I changed the code from the first time I asked this question, so I decided to make a new thread. Sorry if this is not a good idea. Anyway, I'm still getting a Seg fault here. And even if that ...
1
vote
1answer
109 views

What to do with the ASCII key & math?

I'm having a hard time understanding what to do with the ASCII keys & math formula. I understand that you move your plaintext over by the K amount, however, I'm not sure how to write this in code. ...
1
vote
1answer
42 views

Understanding continue statement in while loop in (pset6)

so I am all finished with pset6; however, I am having a hard time understanding what is going on here: while (true) { reset(); if (connected()) { // ..... bunch of other code that ...
1
vote
1answer
635 views

pset5 speller.c with hashtable errors and seg fault

this is my code so far for pset5. I would appreciate giving me hints about my erros. I also get a segmentation fault. thanks. when I implemented load and check only, it seemed to load the text and ...
1
vote
1answer
544 views

invalid operands to binary expression

error: invalid operands to binary expression ('char *' and 'double') printf ("Give me a postive number you want change for.\n"); scanf ("%f", &total_float); roundf ("%f" * 100.0 = "%d", &...
1
vote
1answer
425 views

Writing solutions in C++ instead of C

I know C++ from before starting CS50. If I submit a solution written in C++ for problem sets that deal with the C language, will I get credit for my solution?
1
vote
1answer
1k views

How to Install Stanford CPP Library for Windows (Visual Studio)?

I am using Visual Studio on windows and would like to use Stanford CPP library. Can anyone tell me what is the standard method to include the library header files to run for my visual studio project? ...
1
vote
1answer
118 views

Accessing const int MAX value from helpers.c

I am trying to implement the hacker3 sorting algorithm. The one that requires a O(n). I think I have figured out the algorithm but I won't spoil it by posting any code here. My question is regarding ...
1
vote
1answer
738 views

fifteen.c : printf() not printing anything to the screen

To check the execution sequence of the code, I have added printf statement just below the main(): int main(int argc, string argv[]) { // greet player printf("abc \n"); greet(); ...
1
vote
1answer
24 views

Unable to confirm user input is a number using isdigit in c

My code is attempting to; take user input from the command line; check if the input is a whole number; confirm positively if so; confirm negatively if not; however all numbers return a negative ...
1
vote
1answer
48 views

Lecture 5 Linked Lists: What's going on under the hood?

Sheepishly I must admit I am having difficulty understanding how Linked Lists are implemented. Spent an hour and a half just on this part. The following partial code is from the lecture (comments ...
1
vote
2answers
2k 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 * #...
1
vote
0answers
62 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 ...
1
vote
1answer
248 views

SPEED: python vs C crack program

I have implemented a python and c version of crack way back from problem set 2. Both of them work, and both use the same algorithms/processing just expressed in two different languages. Out of ...
1
vote
0answers
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 ...
0
votes
2answers
207 views

understanding 3D arrays

#include <stdio.h> int main() { int a [2][3][2]={ { {1,2},{3,4},{5,6} }, { {5,8},{9,10},{11,12} } }; printf("%d\n%d\n%d\n", ...
0
votes
3answers
142 views

What is markup language?

I'm little confused with html, it is said as markup language but what exactly a markup language is and how it is different from programming language and scripting languages. Does it need to be ...
0
votes
1answer
595 views

recover.c recovers all images successfully, but check50 says it fails to recover the last. Any ideas why this is happening?

I have a while (!feof(infile)) loop, so that exits only when the eof is reached. And it closes all files upon exit. Here's the code: // scan input file while (!feof(infile)) { // read four bytes ...
0
votes
2answers
259 views

PSET4, Recover - Generated JPGs are blank

My code compiles and saves 50 JPG images with proper names, but when I try to open any one of them, all of them are blank, just grid. When I run check50, I get Segmentation fault error. What I'm ...
0
votes
2answers
915 views

array error: expected identifier or '('

I've just copied a code from a slide explain array creation, but from a lot of tries all come back the same errors "expected identifier or '('". Follows the code: int example [] = { 1, 2, 3 }; for (...
0
votes
1answer
156 views

Comparing arrays in C

Is there a good way (or function) to compare all elements of two arrays (or selected elements) without hardcoding (i.e., while(a[1] == b[1] && a[2] == b[2] && ...)) and without using a ...
0
votes
1answer
92 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
54 views

jpg's are not proper, mix of multiple images. Can anyone tell me whats wrong?"RECOVER"

here is my code while (fread(buffer, 512, 1, inptr) == 1) { if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0) ...
0
votes
1answer
392 views

Caesar Cipher doesn't Print Spaces

So I'm banging my head because my program doesn't print the spaces. For example, if the key is 1 and enter: a b c, it should output: b c d, but right now it's just printing "b" and doesn't recognize ...
0
votes
1answer
88 views

cs50 pset1 mario math wrong or order?

So I'm working on mario less and running into a road block. I got it to output the space and rows and columns but it's upside down, backwards and not the right number of spaces exactly. Like if you ...
0
votes
1answer
68 views

strings an arrays

The question has nothing to do with CS50, so it could be voted as off-topic, but I personally find it curious. The question is that several years ago I wrote a program to convert an array of integers ...

1
2
3 4 5
12