5
votes
Accepted
why can't I compile the program that I wrote to test helpers.c?
this is an example on a program with multiple source code files. C allows you to call a function that is defined in one file from another. we do that all the time (e.g., when we call printf, obviously ...
5
votes
Accepted
How to debug "initialized element is not a compile-time constant" and "expected identifier" errors
You have the right idea behind how the code works, it's just your English to C needs some practice (understandably).
int main(void);
This is, as its name suggests, the "main" method. Essentially, ...
4
votes
Why do I get an "undefined identifier" error even though the variable is defined in my code?
In C all variable names have to be declared before they are used. If you try to use the name of a variable or a function that hasn't been declared you will get an "undeclared identifier" error.
You ...
4
votes
Accepted
pset3 - recursive binary search not compiling
Common problem. The compiler looks at all the possible paths through the code and checks to see that there is going to be a guaranteed, unconditional return to satisfy the need for a return value. But,...
4
votes
Accepted
why do I get "error: expected expression" when I try to compile my binary search implementation?
It looks like the three errors are on lines that call binarySearch(...). The issue is with the array parameter in the call.
When you define the function (when you write the prototype) you need to ...
4
votes
Accepted
How to fix the "expression result unused" compilation error?
It's because you did a calculation and didn't do anything with it. You have cents - 25; Where are you putting the result?
All of these would work:
int change = cents - 25;
cents = cents - 25;
...
3
votes
Accepted
compilation error multi-character character constant in caesar
Simple fix. Look at the line:
int letter = 'plaintext[i]' ;
You are trying to put the integer (ASCII) value of a letter stored at plaintext[i] into the variable letter. The idea is right, but look ...
3
votes
Accepted
pset2 vigenere error "incompatible integer to pointer conversion"
The types char, short, int, long int, and long long int are often referred to as integer types.
Per its manual, the function atoi takes a value of type const char *. I assume your variable named k is ...
3
votes
Accepted
Error: control may reach end of non-void function
It's mostly a duplicate, but it bears repeating and could use a more specific answer here.
Your logic is right in that, assuming there are no issues with the data fed to it, the function will return ...
2
votes
"Control may reach end of non-void function" but I'm sure my else statements take care of it?
Consider following question: what happens, if there is no value in values[]?
In such case, assuming n is greater than 0, we would never reach any of the return statements:
First one wouldn't get ...
2
votes
pset1 "expected identifier error in do-while loop
Happy to help. You're running into syntax errors, which you'll have a lot of as you're getting started. Always best to cure them in order because sometimes the early ones cause a lot of later ones.
...
2
votes
What do these Check50 errors mean?
:( greedy.c compiles
\ expected an exit code of 0, not standard error of "greedy.c:7:4: error: expected identifie..."
That frown :( and the fact that it is displayed in red means that your code ...
2
votes
Accepted
Nothing to be done for `adder'
Make sure the file named adder has the extension .c. Also make sure you're executing this command
make adder
NOT
make adder.c
2
votes
Validating the input in mario.c
You are seeing lots of very strange errors because the compiler is having a hard time understanding the code. The compiler takes things very literally, and if the syntax is not 100% perfect, the ...
2
votes
Can't compile readability in cs50 IDE
I found that when following the instructions to create readability, the newly created tab "readability.c" has a red dot, and when clicked, it prompted me to save. Once saved, it should work. Hope ...
2
votes
Accepted
pset 3 plurality code help
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].votes >= maxvote)
{
maxvote = candidates[i].votes;
winner = candidates[i].name;
...
1
vote
Accepted
PSET2 Vigenere: Control may reach end of non-void function error
You're right. The compiler just knows that there's a possibility of getting to the end of the code without seeing a return statement, so it's unhappy.
However, your fix in the comments has a flaw. ...
1
vote
Accepted
Compilation error in hello.c: undefined reference to `get_string'
Compiler does not complain about missing cs50.h, so that looks right.
The linker does complain, though, and that's probably because you did not pass -lcs50 when compiling (telling the linker to ...
1
vote
Keep getting this compile-time message: error: unused parameter 'argv' [-Werror,-Wunused-parameter]
int key = atoi("argv[1]"); this is using the literal string "argv[1]", not the value stored in argv[1].
Also, you should be checking that argv[1] exists before you use it as an argument to atoi (ie,...
1
vote
Accepted
Keep getting this compile-time message: error: unused parameter 'argv' [-Werror,-Wunused-parameter]
Actually, no, you're not using argv[1].
int key = atoi("argv[1]");
By putting it in double quotes like that, you're telling the code to use the literal string "argv[1]" instead of the var. It ...
1
vote
Accepted
Pset3 - Music: Unused parameters and control reaches end of non-void function errors
There are a few simple issues. First, octave is being declared and then redeclared, but, amusingly, that isn't the actual problem. The real problem is that they are being declared inside of code ...
1
vote
Accepted
PS3's Fifteen won't compile only during check50?
check50 for fifteen replaces the draw function with a simple one whose output is then used for the tests. If your own draw function contains code (setting the values of global variables or calling ...
1
vote
Accepted
strange error message when compiling helpers.c
no function main () in helpers, hence the error when compiling, you only have to type make in the terminal, if you are located in the appropriate directory, by the way the swap function will not work, ...
1
vote
Accepted
What does "using" a variable entail and why does this inconsistency come up? (pset1, greedy, general question)
The root of this problem lies in the order of operations. In C, postfix increment (++) binds more tightly than dereference (*). Thus, what the code *coins++; does is not to dereference coins and then ...
1
vote
pset1 - Greedy Errors "error: expected expression"
The error is created by the compiler finding an else clause without knowing the corresponding if (there has to be exactly one statement or code block in between).
Use {} blocks with your if to ...
1
vote
Accepted
Subscripted value is not an array
The variable a is declared as a single integer. In the line if (a > a[y+1]) this code attempts to compare a to an array of the same variable name. This presents two problems. First, two vars can't ...
1
vote
PSET6 server: Make server error - Please please help =(
Hopefully, this article from Cloud9 support, Code Disappeared or Lost, will help you recover your source code.
1
vote
How to fix the `unused variable` error?
to understand what causes the error, you need to understand three things:
the difference between defining a variable and using it.
scoping.
shadowing.
first off, when you use a variable that was ...
1
vote
Transforming argv[1] into a string of integers
atoi() transforms a string into a number, not a char. As it expects a char* it is telling you to put the & so that it can work with an address.
Also, to fill an int array, try the following:
int ...
1
vote
Accepted
implicit declaration of function getint() is invalid in c99
That's GetInt(), not getint(). C is case sensitive.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
compilation-error × 61pset3 × 9
pset1 × 9
mario × 7
cs50x × 6
c × 5
error × 5
clang × 5
pset5 × 4
speller × 4
greedy × 4
function × 4
pset2 × 3
pset6 × 3
caesar × 3
pset4 × 2
check50 × 2
vigenere × 2
server × 2
cs50-ide × 2
helpers × 2
array × 2
readability × 2
for-loop × 2
variables × 2