20
votes
Accepted
Pset3 Binary Search problems
This is an example of a recursive call. Even though it is calling itself correctly, it is missing the code necessary to recursively return the result. As it is written above, it will execute the ...
4
votes
Pset3 Binary Search problems
There was a question about this question on facebook, so instead of replying there, I thought I'd try to give some examples here, to supplement Cliff's amazing answer. It might be that none of this ...
2
votes
Accepted
PSet3 Find passing my testing but failing check50
What bool does 0 represnet - true or false?
Your search() routine returns a bool, meaning either true or false. However, you have fallen into the trap of using numbers instead of true or false. The ...
1
vote
Accepted
Pset5 - Apostrophe and check problems with Tries
There are several problems. The most significant is this:
for (char* i = buffer; *i != '\n'; i++)
{
// creating a variable to store letters in
int templetter = i[j];
This code is supposed to ...
1
vote
Accepted
caesar argc ... help me get started
Well your program is correct, in the sense that it doesn't have any compiling errors, but it doesn't do anything. It just checks whether the user gave 2 arguments or not. You are correctly returning 1 ...
1
vote
pset3 return function
I would suggest that you visit the CS50 Study page for Functions to get a good basic understanding of how functions work, what it means to return etc. There are several slides, examples, and videos ...
1
vote
Accepted
pset3 helpers.c not working
Hard to see what exactly is going on without getting a look at your wider code but the logic in this loop can't be right.
Your "for" loop will only ever run once because it will return either true or ...
1
vote
Accepted
p2 substitution i have no idea how to return multiple value from same variable in a function since c doesnt take variable array length
I think you might have been bogged down in the details. It's actually quite easy. You don't need to set the size of an array when passing or returning one. Just pass the name of the array var. In ...
1
vote
Accepted
Running an 'if' statement inside of a 'for' loop; Need to continue loop w/o printing anything, but not sure what value to return
First, since not all the relevant code is here, we have to make some assumptions. First, length = strlen(key). Second, this is in main and not in a function that's called by main. Third, the code ...
1
vote
Accepted
Return type of printf in C
you are right, in fact the printf function return value is as follows:
Return Value On success, the total number of characters written is
returned.
If a writing error occurs, the error ...
1
vote
Accepted
End program by returning exit code 0 from bool function
This is a really interesting question. Is it possible? Yes. Is it desirable? In my humble opinion, it's something to be avoided.
Yes, it's possible. There is a function for this: exit(<number&...
1
vote
pset 3 won() function always return false
First, note that you change n only if something is wrong.
Let's suppose that board [0][0] = 1 as it should be. Then, this condition
else if (board[i][j] != n)
{
n = n+ (d*i)+j;
...
1
vote
C : error non-void function search - value (find)
Having the errors multiply shouldn't necessarily be looked at as the code getting worse. Rather, the new errors should be analyzed for what they are. Sometimes an error masks other errors, other times,...
1
vote
Accepted
Will the loop break in case the condition returns some value to the caller method in C?
"Will the loop break?" Technically speaking, no, it won't break. By using a return true statement, the entire function will immediately terminate and return a value of true to the calling code (or if ...
1
vote
Will the loop break in case the condition returns some value to the caller method in C?
Yes, It will. By return keyword your program will be out of current function's scope. So it will be out of that loop.
1
vote
Accepted
This is the code why it is not returning the swapped values
When you call swap() with int a and int b you are not actually "passing" swap() the variables. Instead you are handing swap() a copy of them, more specifically a copy of the value the variables ...
1
vote
This code of triangle problem always give me "true".I can,t find bug in this please find the bug
This is a case where the code is doing exactly what is written, but maybe not what you want. Can you specify what it is supposed to be doing? I don't remember where this comes from in the course, (...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
return × 23pset3 × 6
c × 6
pset2 × 3
recursion × 3
functions × 3
find × 2
binary-search × 2
function × 2
won × 2
pset5 × 1
cs50x × 1
check50 × 1
caesar × 1
load × 1
check × 1
trie × 1
helpers × 1
array × 1
crack × 1
fails-check50-but-works × 1
for-loop × 1
loop × 1
pset2-substitution × 1
datatype × 1