Questions tagged [function]

The tag has no usage guidance.

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

Function returns not working for CS50 readability.c

In CS50 we now have to make multiple functions (I guess they want us to get used to objective-oriented programming for the python part later) and return the value to the main function. When I execute ...
user avatar
0 votes
1 answer
65 views

PSET6 DNA Why is my (count consecutive substrings in string) function always returns 0's?

I tried writing different function variations but my count_dna function keeps returning zeroes (despite having consecutive sequences of STRs in the dna sequences)--can anyone please tell me why? Note: ...
user avatar
0 votes
1 answer
25 views

error : function definition not allowed here pls help

i got this error message pls help $ make triangle clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow triangle.c -lcrypt -lcs50 -...
user avatar
  • 1
0 votes
3 answers
19 views

Error retrieving return values ​from a function

I am currently studying coding in C language and I have doubts about the return of functions, what I am trying to do is the following: Call the number () function and pass 3 values ​​of the integer ...
user avatar
0 votes
2 answers
58 views

Lecture 2 Arrays

I tried using the code David show to average a set of scores in an array. #include <stdio.h> #include <cs50.h> float average (void); int main(void) { int n = get_int("Total ...
user avatar
0 votes
2 answers
80 views

PSET5 Speller Load function skips the words from the dictionary

Struggling with the load function in speller for second week now. What I found using debug50 and placing "printf" between different lines of code is that the fscanf reads every second word ...
user avatar
0 votes
1 answer
34 views

PSET2 Getting segmentation error

Hello so I am doing PSET 2 Caesar and I tried to write a function to tell me if argv[1] is not a integer I want it to print the error message from the assignment. The problem is I'm very new with ...
user avatar
0 votes
1 answer
29 views

Week 2 Lecture - Functions - Valid Triangle

This is from the functions lecture on a valid triangle. I'm not getting any error messages but I can't figure out why the bool valid_triangle (float x, float y, float z) function is not working. Any ...
user avatar
0 votes
1 answer
12 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; } }
user avatar
1 vote
1 answer
43 views

pset 3 runoff help again

I still dont know what to put in for loop :( I still dont know what to put in the for loop for(int k = 0; k < voter_count; k++) { for (int j = 0; j < candidate_count; j++) { ...
user avatar
0 votes
1 answer
77 views

Pset2 Coleman-Lau Index Always Prints -15

I'm struggling with PSet 2 Readability. I don't want to cheat the answers because I am genuinely trying to learn how to think better and improve my logic. I so far have been able to get the letter ...
user avatar
0 votes
1 answer
32 views

Expected expression on "valid triangle" exercise? i thought the 'or' symbol was 2 lines ( || ) what have i done wrong here?

#include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> #include <math.h> // PROTOTYPE THE FUNCTON bool valid_triangle(float input1, float input2, ...
user avatar
0 votes
2 answers
28 views

Can anyone tell me what ive done wrong and breakdown how to properly prototype and deploy created functions?

code: #include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> #include <math.h> // PROTOTYPE THE FUNCTONS & DECLARE VARIABLES int multiply(int ,...
user avatar
0 votes
1 answer
32 views

What's in the bool function parenthesis?

hope everyone is staying safe. I just want to understand what's inside the parenthesis of the vote function in pset3 - Tideman: bool vote(int rank, string name, int ranks[]) What does it mean to ...
user avatar
0 votes
1 answer
946 views

too few arguments to function call, at least argument 'format' must be specified

I run the C program and I get the following errors. 4:20: error: too few arguments to function call, at least argument 'format' must be specified int x= get_int(); /usr/include/cs50.h:82:1: note: '...
user avatar
  • 7
0 votes
1 answer
101 views

Question for Array in C (with function e.g. set_array)

While I was doing cs50 week2. I found something hard to understand. #include<stdio.h> void set_array(int array[4]); void set_int(int x); int main(void) { int a = 10; int b[4] = {0, 1,...
user avatar
  • 5
0 votes
1 answer
47 views

Speller seg faults in unload function

I've tried to fiddle around with my unload function for a while and don't understand why I'm getting a seg fault. It seems that the unload function is running through completely at least once, but ...
user avatar
1 vote
1 answer
415 views

example positive.c explanation of function

1. // Abstraction and scope 2. 3. #include <cs50.h> 4. #include <stdio.h> 5. 6. int get_positive_int(string prompt); 7. 8. int main(void) 9. { 10. int ...
user avatar
0 votes
1 answer
27 views

Define buy or selling function

I am working on pset8 everything is working I have found a snippet of my code which is identical for buying and selling only difference is to subtract or add to current cash. Can someone point me in ...
user avatar
  • 7
0 votes
1 answer
10 views

Analysing Expected runtime

I came across a question to implement an unbiased random function which outputs 0 or 1 using a biased output function which outputs 0 or 1 with probability P for outputting 1. And to predict how the ...
user avatar
0 votes
1 answer
175 views

PSET2 Vigenere: Control may reach end of non-void function error

I wrote a function to return the shift value for a certain character inputted. Where A, a = 0, B,b =1, etc. int shift(char c) { int asc; if (isupper(c)) { asc = atoi(&c) - 65;...
user avatar
0 votes
1 answer
22 views

About the functions

Why does this code not work? I want to understand why I need to create copies of a and b. I understood the whole idea, but the creating process is not clicking with me.
user avatar
0 votes
1 answer
90 views

declaring a function

Im trying to declare a new function to use in vigenere, I want to create a function that will check if an entire string is alphabetical (not just a single character in a string which is what the ...
user avatar
  • 3
0 votes
1 answer
370 views

pow() function of a float

Why the pow function act like this?, shouldn't the computer consider any integer for example the number 3 as float like this 3.000etc? why it produce different results?
user avatar
  • 7
0 votes
1 answer
39 views

PSET3- Game of fifteen, function move();

So, my move function is ALMOST working, but sometimes when swaping numbers both tile AND blank space shows up as a blank space...can you guys check my code? Thanks! Ps..Blank is a global variable, ...
user avatar
0 votes
2 answers
41 views

Give a Function access to earlier value

If the main block of code gets a value from the user, assigns it to an integer, and then changes that interger's value, is there a way for a function (created outside the main block of code) to access ...
user avatar
0 votes
0 answers
829 views

speller.c:217:5: error: redefinition of 'main' int main

I actually received two error messages: speller.c:217:5: error: redefinition of 'main' int main(int argc, char *argv[]) ^ speller.c:20:5: note: previous definition is here int main(int argc, ...
user avatar
1 vote
1 answer
73 views

Why do I get a wrong html file after executing a quote function? pset finance

I am implementing a quote function in application.py. But the result is ridiculous. After I enter a symbol to search for, I get an apology.html(saying Missing Username!), but this apology.html with ...
user avatar
0 votes
1 answer
24 views

Breakout / pause(function) slows the paddle

When I add pause(5) to the while loop, pause function makes the ball not zip around, it also seems to slow down the paddle responsiveness. What do I have to do to get around that? I do understand why ...
user avatar
0 votes
1 answer
55 views

Pset6 - Analyzer.py - Says Undeclared Function

I declared a function called load_words above init() to load in the words. However, when I call my function in init(), it gives the error name 'load_words' is undefined at the lines where I call ...
user avatar
0 votes
1 answer
27 views

PSET3:Find: Code works without the function, doesn't work with the function

So I am working on Selection Sort for Find, Problem Set 3. When I use a function I made called swap to exchange the values, the array is not sorted. Function snippet: if (min != i) { swap(values[...
user avatar
0 votes
1 answer
67 views

What does "using" a variable entail and why does this inconsistency come up? (pset1, greedy, general question)

During the greedy problem in pset1 I wrote this function: void greedy(int coin_type, int *change, int *coins) { while (*change / coin_type > 0) { *coins++; *change -= coin_type;...
user avatar
1 vote
2 answers
110 views

Pset4 recover.c compiles, but can't seem to print Jpgs at all

Am starting a new thread as I'm having trouble understanding what is wrong with the code.. I've added printf statements at the jpgCheck function and did not get a print. I suspect it's the function? ...
user avatar
0 votes
2 answers
340 views

(PSET 1) Creating functions for water.c. Dont understand how this function worked. (Contains pset answer)

I'm doing water.c of pset1 and wanted to use functions to practice and understand it more. After getting so many errors, I finally got it to work but I don't understand why and how it worked. How is '...
user avatar
0 votes
1 answer
242 views

Why does this recursive factorial function hit segmentation fault?

This is the recursive function I'm using to calculate the factorial of an int. It compiles fine but when I run it, the program hits segmentation fault. The function receives an int taken from the ...
user avatar
0 votes
1 answer
66 views

PSet 3 - Game of fifteen - draw tile gives weird output

I have not been able to draw the board properly. Whenever i run the code ~/workspace/pset3/fifteen/ $ ./fifteen 4 WELCOME TO GAME OF FIFTEEN 15 14 13 12 11 0 0 4196528 0 0 -186283616 32766 48 -...
user avatar
0 votes
1 answer
731 views

Use of functions and variable declarations outside main() on pset1 greedy

I have completed greedy from pset1 and I still doubts about the variable declarations and the function position. What is the difference if they are declared inside or outside the main function? #...
user avatar
  • 1
0 votes
1 answer
70 views

CS50 pset 5 cannot load

I have been working on pset5 for a while. This compiles but load 0 words. http://pastebin.com/Kncw3V8g
user avatar
  • 103
0 votes
1 answer
114 views

pset6 parse: char* pointers are right in parse but return wrong value

I am having trouble with this pset and I am using gdb to step through the function. Should I worry about the following observations or should I ignore them and assume my problems are from something ...
user avatar
0 votes
1 answer
42 views

Why does PrintName return void?

Okay so in the PrintName function, it contains a printf function. However, I read that printf returns a value which is the number of characters. Shouldn't PrintName hence return an int as well? Thanks!...
user avatar
0 votes
1 answer
485 views

Difference between Pass by Value and Pass by Reference (a practical example)

at the end of Doug's video on arrays he explains how variables get passed in function calls in comparison to how arrays work. void set_array(int array[4]); void set_int(int x); int main (void) { ...
user avatar
  • 21
0 votes
0 answers
138 views

pset5-Testing load function separately2

I have been trying to test load function separately (Using Zamyla video for some guidance). I have watched this tape several times, but still unable to load function without compiler errors. I am ...
user avatar
  • 99
0 votes
1 answer
508 views

pset5-testing load function

Ihave been trying to test my load function separately,since I have not implemented other functions,size,check,unload . I have got the following Clang error " expected identifier". I do not know how ...
user avatar
  • 99
0 votes
0 answers
100 views

pset5 load function mallocs more new then i expected, am i building the trie wrong?

With the answer and tips from Cliff B i've managed to stop segfaults and loosing data in the memory, but still unsure about trie implementation. Here's the current code: bool load(const char* ...
user avatar
0 votes
1 answer
22 views

How to end with an unsuccesful memory allocation?

when allocating memory, it is recommended to manually check whether the allocation was successful (or more accurately, terminate the program if it wasn't). Main: int main (void) { char *c = ...
user avatar
  • 58
0 votes
1 answer
26 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 (...
user avatar
0 votes
1 answer
24 views

How do I use my own function for ball movement and call it in main, rather than writing it in main

I've successfully written code inside the while loop in main that makes the ball bounce correctly. However, first I tried to call a function from main (just to make it easier to read), called ...
user avatar
0 votes
1 answer
70 views

space between function name and variables e.g. int main (void)

I checked the style guide https://manual.cs50.net/style/ and the C99 Standard https://en.wikipedia.org/wiki/C99 And neither explicitly states the best format but both implicitly write out main as so ...
user avatar
2 votes
2 answers
75 views

Could we declare the main function as "main () {}" rather than "int main (void) {}"?

In the examples in week 1, we declare the main function as follows: int main (void) { // code } Why do we use int? Is it wrong to use the following instead? main () { // code }
user avatar
  • 25
1 vote
1 answer
612 views

scratch global functions

PSET01 Quick question about Scratch, can you set global scoped FUNCTIONS (or blocks?) that i can reuse across sprite scripts? Example would be creating a custom animation function for "next costume", ...
user avatar