Unlike Java in C, the declaration is usually separated from the definition of functions. It is common for the definition to go in a file .c
and the statement stays in a file called header .h
. But that’s not mandatory.
Contrary to what many people believe the prototype (function statement) is necessary only when it will use in external file - the intention here - or when there are cyclical references between functions. The way used in the question is totally disposable if changing the order of functions.
When going to use other file functions the common is to use the #include
that .h
to include definitions and the compiler to know how to treat that.
All codes in general .c
need to be compiled. This is done manually. They also need to be linked together somehow, whether during the compilation or later, when you already have something pre-compiled.
The question does not give enough information to give a more detailed answer, but it would be basically what you have done with language components:
#include <seuOutroArquivo.h>
Of course, you don’t always have to do this. It depends on the context, the specific case you’re making. To decide the right way you have to learn the whole, understand the philosophy of language.
In this file would have something like that (I’ll guess since the question does not help):
int algumaRegraDeNegocio(int);
And then in a file .c
would have something like this:
int algumaRegraDeNegocio(int valor) {
//faz alguma coisa aqui
return 1;
}
I put in the Github for future reference.
Obviously this is a huge simplification.
To better understand the functioning of header.
Behold: What is the difference between declaration and definition?
Note that there is a very large distance between Java and C. If you try to play in C what you did in Java will go very wrong. I say that because it sounds like you’re trying to use one another’s philosophy.
C has no classes. No hierarchy above. No questions there. No business rule described. All that is described is meaningless and in that form there is no way to answer that question. You need to put something more contextualized, really show what you’re doing, and what problem you want to solve.
– Maniero
It is because I am now starting the code... The code is to make a game of worth using Computational Intelligence. I know that C has no classes, I say call the "files. c" in the file "main. c". In the case the question there is " //PANEL - MENU printf(" nEscolha:"); printf(" n(1)- Player x Player"); printf(" n(2)- Player x PC"); printf(" n(3)- PC x PC");" ... I don’t want to put the scanf in main. c, I want to create another "file. c" put the code in, only the main. c will call this file to display the choices.
– user50860
I think it’s best to post a question when you have something more concrete and clear, in the current form there is no way to answer the question.
– Maniero
I improved the question @bigown, understand now?
– user50860
Improved. Prefer to put the code to make it easier for others who will answer you. Images are not useful. In fact it would be good to put the code of the other file also, indicating this clearly.
– Maniero
Did any of the answers solve your problem? Do you think you can accept one of them? If you haven’t already, see [tour] how to do this. You would help the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.
– Maniero