Questions tagged [c]

The tag has no usage guidance.

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

Recursive Binary Search Exit Code Errors

I wrote the following recursive binary search function. No matter which exit codes I use (e.g., true, false, 1, 0, -1, "Swedish Chef"), I fail at least two of the checks I need to pass. The code ...
0
votes
1answer
222 views

My server.c parse function fails in cs50 check

I have updated this according to your suggestion. And it is giving different results everytime with check50.sometimes it says some are right and other times others are right. I am totally confused ...
-1
votes
2answers
93 views

Why doesn't this work?

I have created two things for pset2 a caesar cipher encryptor and decryptor. My encryptor works and it is called caesar.c, but my decryptor(decryptor.c) doesn't work and I can't figure out why? Here ...
0
votes
1answer
81 views

i am getting segmentation fault with my recover.c program

include include int main(void) { FILE* file = fopen("card.raw", "r"); int* data = malloc(513); if(data == NULL) { printf("failed to do task\n"); return 1; } else { int k = 0; ...
0
votes
1answer
940 views

Debugging Webserver in C

I have an error in my server.c file for PSET6 but have no idea how to find it. I am trying to use GDB and it does not seem to be very useful. I would love some help learning how to better debug this ...
0
votes
2answers
906 views

Problem printing spaces on Mario

I've been looking here on Stack for a solution to my problem and couldn't find one. My code seems to work properly, besides the spaces that looks like, are not beeing printed. Here's the code: int ...
0
votes
1answer
66 views

Pset4 Recover Writing the slack space on Jpg

My code for recover works fine but I'm having a little trouble understanding one thing. Here is a snippet from my pseudocode -found the first JPG's signature? While true Write the buffer ...
0
votes
1answer
124 views

Game of Fifteen Move Function Duplicates Tile

In my Game of Fifteen code, the move function for the most part works, but once in a while, a tile will duplicate, looking a bit like this 1 1 2 4 5 6 7 8 _ As you can see, the number 3 ...
0
votes
2answers
103 views

My hash table works and has good running time but fails one check - :( handles max length (45-char) words

My hash table works and has good running time but fails for one check (rest all checks pass) - :( handles max length (45-char) words AFAIK pneumonoultramicroscopicsilicovolcanoconiosis is the longest ...
0
votes
1answer
402 views

"Error: control may reach end of non-void function". What causes this error? [duplicate]

I'm working with code (that I am not the primary author of) and trying to get it to run. It tests to see if a number is prime or not. It gives me the error error: "control may reach end of non-void ...
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 ...
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
1answer
328 views

sys/resource.h in speller.c Where is it and how can I open it?

So trying to following the instructions in pset5: "Don’t move on until you’re sure you understand how speller itself works!" I have found myself unable to locate resource.h I look for it in /usr/...
0
votes
2answers
895 views

Resize - Which function to use to write in a RGBTRIPLE buffer?

I am having some trouble in the following code : void bufferwrite(RGBTRIPLE rgb, RGBTRIPLE* buffer, int n, int padding) { fwrite(&rgb, sizeof(RGBTRIPLE), n, buffer); for(int i = 0; i <...
1
vote
1answer
15 views

copy.c:70 Is the second %4 needed?

This code here: // determine padding for scanlines int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; is the second %4 necessary? wouldn't int padding = 4 - bi.biWidth * sizeof(...
0
votes
2answers
447 views

Error: Expected Expression with an Array

I'm working on implementing a binary sort. I don't understand the error in my code. I'm getting that error 3 times, on line 24, 43, and 48. Those are the three conditionals with the find(value, low, ...
0
votes
1answer
102 views

pset2 initials.c validation returns unexpected test results

I'm not sure where to direct this question, but on validation my initials.c program i got unexpected errors, for example: :( outputs "R" for "ROB" \ expected output, but not "RO\n" :( ...
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 ...
0
votes
1answer
87 views

Vigenere.c and modulo issue

After banging my head on the desk for the past few days I've decided to post. My problem is with vigenere.c. I figured I had a pretty solid understanding of the algorithm used to create the ...
4
votes
4answers
7k views

Memory overlap in C

So I am learning C and I have to implement the memset() and memcpy() functions. I've looked them up in linux man pages and I saw that the first takes care of overlapping memory situations but the ...
0
votes
1answer
25 views

Pointers in a function

Can someone please explain, why list-printing cycle with pointers works perfectly fine from main(), but refuses to work from separate function when called. #include <stdio.h> void listPrint (...
0
votes
1answer
118 views

What format is the PHP interpreter expecting a query?

I've managed to successfully extract a query from the target, but in order to configure it properly I need to know what to put into the "query" string variable. I've hunted a bit and experimented but ...
0
votes
1answer
24 views

Problem detecting the bricks in breakout

I am now working on on pset3. The problem is that I can't detect when the ball hits the brick. I tried many different approach and read the previous post about this problem but I can't find why it's ...
0
votes
2answers
158 views

CS50 pset2 Caesar's cipher - Compile but doesn't work?!? GetString() above and beyond

I'm working on pset2, Caesar's cipher part. I understand how to proceed to do the encryption and my program compile well. The first line of command allow the user to correctly enter his key. After the ...
0
votes
1answer
48 views

greedy outputs are correct , but check50 complains all of them

Problem was due to a really case sensitive checker. Thanks for help. And sorry for posting the whole code.
3
votes
1answer
793 views

pset 1 greedy: how to properly convert float to int

My problem is specifically how to convert the float that the user gives (dollars), into an accurate integer (cents). My code: printf("O hai! How much change is owed?\n"); float change_owed = ...
0
votes
0answers
69 views

What to do in Pset 6 Web Server? [duplicate]

Up until Pset 5, CS50's lectures, shorts and walkthroughs were pretty helpful in not getting me stuck at a problem. However, as we transition to web based programming, I'm entirely clueless about what ...
0
votes
1answer
221 views

Check function error integer to pointer conversion

I keep getting this error but am at a loss as to how to solve it! It's driving me crazy and getting frustrated with it. incompatible integer to pointer conversion passing 'int' to parameter of type '...
0
votes
2answers
418 views

Developing JPEGS for pset4's recover troubleshooting

I am currently working on cs50's pset4 recover. I have managed to compile the program. However, when run, the images are corrupt and apparently, according to image viewer, are not jpeg files, because ...
0
votes
3answers
568 views

Assing argv[1] to a string variable (vigenere)

I'm stuck. There's a way to assign argv[1] to a string variable?, like: string keyword = argv[1];
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(...
0
votes
1answer
57 views

Create an array for a case statement - confused

I am a bit stuck on how to create an array so i can create a string to declare a colour. I have the following code: char[7] color; //biggest color: yellow (6) + \o (1) = 7 for(int i = 0; i < ...
0
votes
1answer
33 views

Pset 6 Adding Strings and ssize_t?

I have a question on adding strings and data types. What does it mean to use them in such arithmetic? Does body + size mean that it is creating a new block of memory that includes both of them? The ...
0
votes
0answers
61 views

My code doesn't run %s?

Here is the C programming Absolute Beginner's Guide book's chapter15ex1.c //Example program #1 from Chapter 15 of Absolute Beginner's Guide //to C, 3rd Edition //File Chapter 15ex1.c /* This program ...
0
votes
1answer
644 views

Speller - trie implementation - Segmentation Fault

Having some trouble with a trie implementation of speller pset5 (2014). It seems to almost work, finding misspelled words, but then I get a segfault. It appears I have some memory problems, and I ...
0
votes
1answer
198 views

2014 pset5: Double free in load

I can't seem to figure out how to allocate and free memory correctly when I'm using a linked list node (a pointer inside a struct). When I can get my code to run without error I am getting major ...
2
votes
1answer
2k views

Does only malloc allocated memory on the heap?

Does only malloc() allocate memory on the heap or when we use pointer and normal variables put some value then it will be stored in some memory location on heap. To be clear, below are cases: //...
0
votes
3answers
178 views

pset1 mario. can't fix errors, please help!

I can't understand what's wrong with the code. I've changed it many times, but errors are always similar.Can anyone please check the code and tell what's wrong?
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", &...
0
votes
1answer
6k views

How to iterate through an array using pointers

I managed to "solve this issue", but I don't know why I get the problem I get. Right after the last line I also got a segmentation fault, which I failed to include in the above screenshot. My ...
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 ...
0
votes
3answers
180 views

PSET 1 Mario Code Problem

Would someone be as kind as to tell me what I got wrong for this section of my code? Thanks so much in advance!
0
votes
2answers
913 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
342 views

to what extent does CS50 teach the different languages? [closed]

There are many languages taught in CS50. javascript, css, html, c, [tag: PHP], etc. To what extent are they taught? Can I make my own websites after CS50 ? To what extend do I have to learn these ...
0
votes
2answers
502 views

Can't pass pointer to strcat function

I'm trying to concatenate a string to another string using strcat function available in string.h, it compiles successfully but on execution, it gives segmentation fault (core dumped) message on ...
0
votes
1answer
3k views

Conversion of hexadecimal to floating point

Does anybody know any way of conversion of hexadecimal to floating point? Any C, Java, C++ or any language's program that could automatically convert it or the formula to convert it manually on page ...
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
0answers
26 views

General Code Writing Question in CS50

I guess this is a general question regarding the Psets from this class.. So far, I've only done pset1 and pset2, and while my code "passes" all the checks, how do I know I am writing them the way a "...
0
votes
1answer
13 views

Why do I get an error when trying to evaluate a polynomial in C?

Does anyone know what I'm missing? #include <stdio.h> int main(void) { float y = 2.55; float total = 3(y)(y)(y) - 5(y)(y) + 6; printf("%f\n", total); return 0; }
0
votes
1answer
49 views

What are threads in C?

Please explain what threads are in C language! I'm referring to CS50 week 0 - shorts.

1
8 9
10
11 12