Questions tagged [c]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
21 views

does function prototype effect's speed of c terminal?

I am watching cs50 lecture 1 C. following the lecture, I got curious about the function prototype. tutor mentioned it as convenient and traditional to use it. but for computer side - Isn't difficult ...
0
votes
1answer
80 views

Confused with Caesar Cipher Formula

So once I have the letter's number like: 0 A 1 B 2 C etc, ...and the key, let's say I'm encrypting Z (25) and shift by 1, using the given formula: ci = (pi + k) % 26 . --> ci = (25 + 1) % 26 --> ...
2
votes
1answer
526 views

UndefinedBehaviorSanitizer:DEADLYSIGNAL, what does that mean?

What does UndefinedBehaviorSanitizer:DEADLYSIGNAL ==752==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000439000 (pc 0x000000428b5b bp 0x7ffdc38f56b0 sp 0x7ffdc38f5380 T752) ==752==...
0
votes
2answers
177 views

pset2 crack: Takes too long

My code takes like 1-2 minutes to execute, and the result is always Killed. Here is my code: #include <cs50.h> #include <stdio.h> #include <crypt.h> #include <string.h> ...
0
votes
1answer
75 views

Why isn't resize(more) printing properly?

I am back again with another question about resize more. I feel like I am pretty close, but for some reason it is not resizing vertically properly when the factor is larger than 0 (I haven't dabbled ...
0
votes
1answer
27 views

pset3/resize same expexted sizes for different scales

While resolving resize(less) problem I've encountered check50 expects the same sizes of files with different scales. How could that be? :( doesn't resize small.bmp when n is 1 Header field biSize ...
1
vote
2answers
210 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> // ...
0
votes
1answer
361 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
226 views

pset1 Cash: Having a hard time understanding the flow of the app

I wrote this following code as solution to the pset1 cash problem, it compiles and runs but once the user inputs the owed amount it replies with 0 coins to give back, which is false. #include <...
0
votes
1answer
57 views

Why is my ciphertext printing random values?

I am currently working on Vigenere. I have the code to where it will work if the key is very short (a few characters), but for some reason my program bums out when the plaintext is long or the key is ...
0
votes
1answer
54 views

Why isn't my key running cyclically?

I am currently working on Vigenere, and for whatever reason my key values are running through randomly and just not working. I'm new to programming, so sorry if I am missing something major in my code ...
0
votes
2answers
265 views

Pset 3 (Recover): Why are images still glitchy?

I've been having trouble with pset3's Recover exercise. My code successfully compiles and creates 50 jpegs, numbered 000 to 049. However, all images are terribly glitchy. Examples: I've scoured the ...
0
votes
1answer
3k views

When compiling I get an error: note: expanded from macro 'get_float'

When I try to compile with make file, I get the following error /usr/local/include/cs50.h:177:91: note: expanded from macro 'get_float' #define get_float(...) __extension__ IF_ELSE(ISEMPTY(...
0
votes
1answer
405 views

CS50 Speller (hash table) - Check returning 0 misspelled words

I'm looking for help with my (hash) code in check to properly handle misspelled words with apostrophes and substrings: bool check(const char *word) { int len = strlen(word); char copy[len + 1]; ...
1
vote
1answer
427 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 ...
0
votes
1answer
101 views

PSET4 RECOVER (QUESTIONS)

I managed to make my code recover all 50 images, and have passed check50. However, during the development process I have encountered two problems, and still doesn't get why it is an issue. Here is my ...
0
votes
1answer
542 views

switch case inside do while loop - not looping

Hi could anyone please help me? I try to do a code , where after choosing with switch - case, what function you want to run, it gives you opportunity to turn back to "menu" - switch, and the same if ...
0
votes
1answer
55 views

Memory leaks on unload

All tests pass except the valgrind check at the end. I am sure that my unload algorithm isn't correct, but I checked like 5 times, and I can't find logic flaw. I don't need solution, just a hint ...
0
votes
1answer
145 views

Memory leaks in Speller

My program passes all tests except the valgrind check. I tried to find the cause of errors, but valgrind is too 'obscure' for me yet, I don't know what to do. I guess some memory isn't freed, but I ...
0
votes
1answer
67 views

My “vigenere” code strange result

My code compiles and I tested it with the example "Meet me at the park at eleven am", the result was "Negh zf av huf pcfx bt gzrwep oz", and that is correct. But when I run "check50 cs50/2018/x/...
0
votes
1answer
24 views

i want the number of line in which the function is locate , like the function “func2” is in second line so the output shoud be 2 [closed]

#include<stdio.h> #include<string.h> unsigned int FindFunctionDefn( char strFunctionName[], char strSourceCode[] ){ int n = strlen(strSourceCode); int m = strlen(...
0
votes
2answers
238 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
1answer
63 views

Can't open generated JPGs

My code compiles and saves 50 JPG images with proper names, but when I try to open any one of them, I get the 'Invalid or Unsupported Image Format' error. What I'm doing wrong? Here is pseudo-code: -...
0
votes
2answers
21 views

do a+b while its not divisible by c

I am completely new to C and also programming, and I have to make algorithm for: a=2 , b=3 and add "b" to "a" and display results of it until its divisible by 7 I tried something like this but I cant ...
0
votes
1answer
23 views

Why string variable has no square bracket?

Though it's said that string is an array of characters why string variable does not have square brackets on the immediate right? In CS50 we call string as string s why not as string[]? then how can ...
2
votes
1answer
1k views

:( recovers 049.jpg correctly recovered image does not match

I have problem with pset4/recover. I recover all images and can see last image when I click on it but when I run check50 it returns with error: :( recovers 049.jpg correctly recovered image does not ...
0
votes
2answers
5k views

How to print a long number in C?

Hello I am very new to C but have some experience with python and would like to know how to print the outputs for the credit.c so I know what I am dealing with. I have this code and when I get to the ...
1
vote
1answer
212 views

array size in C

I have question regarding array size declaration in C. I see that if I declare an array in the main function without specifying its size like int arr[]; arr[0] = 7; arr[1]= 8; it shows an error ...
0
votes
1answer
38 views

mario and problems with my array

# include <stdio.h> #include <cs50.h> So I've been playing around with this problem alot and unforturnatly asked many questions. But I think I've figured out the basics, if not back to ...
0
votes
1answer
85 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 ...
1
vote
2answers
55 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 ...
0
votes
0answers
53 views

Expected identifier or '(' and undeclared identifier ERROR (PSET2 Vignere)

Hi all, I'm getting 6 errors from my code, stemming from two main reasons: Expected identifier or '(' Use of undeclared identifier I can't figure out what went wrong my code even after inspecting ...
0
votes
1answer
43 views

Trouble with the hacker edition of mario.c

I have been struggling with the hacker edition of mario.c for over 2 hours. If I give a height of 5 I only get 4 rows as shown in the attached image. /* C Program which prints mario's right aligned * ...
1
vote
2answers
219 views

I can´t get (pset1) greedy/cash.c pennies to work properly!

i´ve been trying to figure out what is wrong with my code for the pset1 cash or greedy program, i know about float imprecision but when i print the last value for "ch" it prints .01000, thus meaning ...
0
votes
2answers
56 views

Is it possible to create/declare alphanumeric variable inside a for loop in c?

I want to create multiple variables like P0, P1, P2. The range will be given by the user. How to solve this in C?
0
votes
1answer
497 views

Receiving 'error: expected expression' for code inside if statement (pset1)

Originally, my if statements looked like these (please note that I didn't really write them one after the other like this): if (counterCardLength == 15 && FindFirstTwoDigits == 34 | 37) if (...
0
votes
1answer
1k views

pset1 | error: invalid operands to binary expression ('long long *' and 'int')

Here are snippets of my code: long long card = get_long_long(); long long *FindLength = *card; while (FindLength != 0) { FindLength = FindLength / 10; counterCardLength++; } And ...
1
vote
1answer
7k 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 ...
0
votes
1answer
15 views

My for loop in vigenere will not execute

The for loop is not running and I cant figure out why. Everything looks good to me. I need some fresh eyes. Thanks guys! #define _XOPEN_SOURCE #include <stdio.h> #include <unistd.h> #...
1
vote
1answer
42 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> #...
0
votes
1answer
54 views

Pset1: Error when trying to assign single digits of int variable to array using for loop

I'm currently working on Credit. I'm trying to find the first two digits of the card number using a for loop. I've created an array named firstdigits with two elements. Then I've created a for loop to ...
0
votes
1answer
614 views

How to find the length of a number

I'm working on Credit and am at the point where I have completed all the required calculations on the credit card and now need to find out if the final sum ends in zero or not. I think that in order ...
0
votes
1answer
8 views

How can I ensure I'm changing the reference, not a copy, in this C function?

I'm trying to assign a pointer to a pointer within a function. I've passed pointers in and I'm trying to make the change inside. It is not happening, however. The issue is regarding the insert ...
0
votes
1answer
32 views

pset5 memory leak: should freed memory but didn't

I need to operate p in the for loop, therefore I made a copy of the p pointer, and I free p_malloc_orig at last. But the memory is acutally not freed. Where did I possibly do wrong? char *p = malloc(...
2
votes
2answers
280 views

pset4 recover: recovered images seems to still be corrupted

My code compiles and runs without any errors. Images are generated, but the images are incomplete, here's an example of 000.jpg: https://i.imgur.com/Ovs2Xv8.png. I can't really find what's wrong in my ...
0
votes
1answer
81 views

pset4 recover: first byte of buffer seems unexpectedly changes to 0

Thanks for seeing my question, I appreciate your help. :) Let's get to the point. My code compiles and runs without any errors. Images are generated, but the images are incomplete, here's an example ...
0
votes
1answer
63 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 ...
0
votes
1answer
119 views

Pset5 unload: how can I update Trie's data inside a recursive function?

few people suggested to use a recursive method of unloading a Trie data structure, but I am struggling with it a bit. I am stuck on the part on how can I update the root node ( the main node which ...
0
votes
1answer
29 views

Trouble with mario.c using function

When I run the below program, I get the following output. Height: 10 # Height: 15 ## Height: /* Copied from https://www.reddit.com/r/learnprogramming/comments/68hp3e/...
0
votes
1answer
61 views

Error in my submission for CS50 Pset2 Caesar. New line placement is wrong

#include <cs50.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, string argv[]) { //Check if there is 1 command-line ...

1
3 4
5
6 7
11