hello friends
i finally started programmation at school, we use ubuntu, at home i installed eclipse with MinGW i tried simple helllo world and it works but when i start mutiple exercices under same same project i get a compiler errormultiple definition of 'main' in c i tried
int main (){} same problem i tried int main (void){} same problem please someone help me.

Recommended Answers

All 3 Replies

Because you're writing all your code in one project, you're trying to combine all your code into a single program. You're only allowed one function named main in a single program. Because you wrote lots of functions named main, you're breaking that rule.

Separate project for each exercise.

Besides that the main funcition is a special funcition, it's the entry ponint of the program, you cannot have multiple functions with the same name defined when you write pure C programs where the name are not mangled. That is, if you have defined one fucntion foo() in your project/program, you cannot define another function named foo in your program.

i got it, but now i have another problem with eclipse when i have i scanf in code i must first enter type something for the scanf and even if scanf was at the end of block for exemple this code i must enter the value of x then the program ecute normam

#include <stdio.h>
int main(){
    int x;
    printf("enter the value of X: \n");
    scanf("%d", &x);
    printf("The value of X is: %d\n", x);
return 0;
}

and this is what i get i console

5
enter the value of X: 
The value of X is: 5

i enter first the value of x then the program start.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.