Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I would like to make a simple calculation in C.
Nverthless, there might be a problem in my code with the "resultat"...
Was trying to do the exemple given in OpenClassroom, at the following link : https://openclassrooms.com/fr/courses/19980-apprenez-a-programmer-en-c/14337-une-bete-de-calcul
Here is my code in Repl.
I think the teacher didn't put everything for it to work properly, so I've tried to modificate it by puting the two first lines : https://repl.it/#LunaShivaya/SuburbanThornyDebugmonitor
Thanks in advance for your ideas :)
Sakura.
You need to declare it inside a main function.
#include <stdio.h>
int main()
{
int resultat = 0;
resultat = 5 + 3;
printf("5 + 3 = %d", resultat);
return 0;
}
Libraries are used to load pre-defined variables and functions. In this case, you are using printf, which is pre-defined in the library stdio.h.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 11 months ago.
Improve this question
I just wondered, is there a way to define a macro in C to replace it for certain symbols that I print ? I tried something similar to defining number values, like #define NUMBER 7, but I haven't managed to do the same for characters. Googling hasn't given me a proper answer either. Is something like defining characters by macros even a thing in C ? Thanks for your advice !
I believe this is what you are looking for
#include <stdio.h>
#define mystr "HELLO WORLD"
int main()
{
printf("%s", mystr);
return 0;
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
int main()
{
bool loop = true;
while (loop)
{
loop = reservationCycle();
}
return 0;
}
i keep getting error: ‘reservationCycle’ was not declared in this scope
You havent declared the prototype of that function reservationCycle() It means the compiler doesnt know what reservationcycle is.. you should declare and define the whole function first before using it in main()
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
can I use post-increment in a function return in C like this?
int meta_solve() {
//some codes
return metaData[head++]; //head is global variable
}
I asking this question because it showing the different results on windows and mac. thanks for your attention. have a great day!
Yes, that will work.
The return will not happen until the expression metaData[head++] is fully evaluated so the (global) variable head is incremented before the function returns.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
When I implement my code, my function does not work. However, I don't know the reason why. Can you tell me some problems and how to solve it?
Here's my code! And I'm using language C!
You are calling the function in wrong way:
try this:
findMin(n,arr);
findMax(n,arr);
Whenever you are calling function: in function just pass the array name;
Whenever you are calling a array in function just write its array name without [] bracket.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I wrote a program to show the capital letter of a given small letter, but in the output console it's showing an error.
#include <stdio.h>
int main
{
char small_letter, capital_letter;
printf("Please enter a small letter: ");
small_letter = getchar();
capital_letter = small_letter - 32;
printf("The capital letter is: %c\n", capital_letter);
return 0;
}
The error seems to indicate you have multiple main functions. It looks like both of your files are being compiled together. In order to compile try renaming or deleting one of your main functions.
To explain a little further this is a linker error caused when the linker is not sure what is meant. In C you can declare functions with the same signature multiple times but you cannot define them multiple times.