As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [function]

The tag has no usage guidance.

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

where am i making mistake here? problem set2 substitution

hey here i am trying to return 0 if argument string contains all 26 alphabet characters otherwise function should return 1 and print message]1 ]
Abhi's user avatar
  • 1
0 votes
0 answers
14 views

Pset1/ cash without creating functions

Why should we create function, while we can do the same thing in a simpler method. the number checks worked correctly but when I tried check5o, it got me the yellow face. Also I am so confused, when ...
Mayar Ashraf's user avatar
0 votes
1 answer
59 views

PSET 2 Readability: undefined reference to `count_letters'

I'm receiving the error: /usr/bin/ld: /tmp/readability-1786f7.o: in function main': /workspaces/109105972/readability/readability.c:19: undefined reference to count_letters' clang: error: linker ...
Jaron Haberstroh's user avatar
0 votes
1 answer
38 views

Error when calling seconnd function - expected expression

I'm trying to call my encryption function and am getting an undeclared identifier error. Not sure where i'm going wrong. Code: #include <cs50.h> #include <stdio.h> #include <ctype.h> ...
tsull's user avatar
  • 1
0 votes
1 answer
71 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 ...
Max Grossenbacher's user avatar
0 votes
1 answer
93 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: ...
General Noob's user avatar
0 votes
1 answer
208 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 -...
dh45r's user avatar
  • 1
0 votes
3 answers
26 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 ...
Code Maker's user avatar
0 votes
2 answers
85 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 ...
Multiplify's user avatar
0 votes
2 answers
146 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 ...
Alexander Alexandrov's user avatar
0 votes
1 answer
46 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 ...
Dre Johnson's user avatar
0 votes
1 answer
73 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 ...
Leonidas Smiley's 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; } }
Sandro Docanto's 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++) { ...
iliketurtlz's user avatar
0 votes
1 answer
87 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 ...
user5854648's user avatar
0 votes
1 answer
34 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, ...
Pot Noodle's user avatar
0 votes
2 answers
33 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 ,...
Pot Noodle's user avatar
0 votes
1 answer
40 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 ...
ZeevKeane's user avatar
0 votes
1 answer
1k 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: '...
mikeli's user avatar
  • 7
0 votes
1 answer
137 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,...
Minsu's user avatar
  • 5
0 votes
1 answer
56 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 ...
ShippingTycoon's user avatar
1 vote
1 answer
459 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 ...
Sheikh Munawar's user avatar
0 votes
1 answer
43 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 ...
Pierre's user avatar
  • 107
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 ...
ULTIMATEGAMER07's user avatar
0 votes
1 answer
176 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;...
Amanda Ramirez's user avatar
0 votes
1 answer
47 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.
Nourdine Dali's user avatar
0 votes
1 answer
98 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 ...
mesi_'s user avatar
  • 3
0 votes
1 answer
475 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?
Sengo's 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, ...
Lucas Ribeiro's 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 ...
Chaim Tzvi Kalish's user avatar
0 votes
0 answers
947 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, ...
KitSeason's 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 ...
wingedRuslan's user avatar
0 votes
1 answer
26 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 ...
wingedRuslan's user avatar
0 votes
1 answer
56 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 ...
SuperNovaCoder's 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[...
Satanic Saint's user avatar
0 votes
1 answer
72 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;...
Chris Offner's 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? ...
olafironfoot's user avatar
0 votes
2 answers
341 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 '...
Dulguun's user avatar
0 votes
1 answer
281 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 ...
Iury Sikorsky's 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 -...
Dhawal Patel's user avatar
0 votes
1 answer
973 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? #...
msaitz's 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
Ichi's 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 ...
Brendan Rafferty's user avatar
0 votes
1 answer
47 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!...
user107224's user avatar
0 votes
1 answer
530 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) { ...
Alberto's user avatar
  • 21
0 votes
0 answers
141 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 ...
uma1966's user avatar
  • 99
0 votes
1 answer
510 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 ...
uma1966's 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* ...
user10187's 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 = ...
Vincent's 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 (...
Trujaman's user avatar