473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

error: redefinition of ‘main’

Hi

here is the error I got after executing the program

prog.c:12:5: error: redefinition of ‘main’
int main() {
^~~~
prog.c:3:5: note: previous definition of ‘main’ was here
int main() {
^~~~

#include <stdio.h>

int main() {
#include <stdio.h>

return 0;
}
Jan 9 '18 #1
2 37547
weaknessforcats
9,208 Expert Mod 8TB
Function names must be unique. You cannot have two of the same name because the compiler can't determine which one to call. The error has nothing to do with the name "main". It has only to do with having more than one function with the same name.

BTW: You show an include of stdio.h inside main. All includes should be outside any functions.
Jan 9 '18 #2
donbock
2,426 Expert 2GB
The error messages suggest function main is defined twice in your source file (perhaps once on line 3 and again on line 5). However, the code snippet you provided shows only a single definition of main. If in fact your code only defines main once then something else is going on.

Perhaps this error is an artifact of including <stdio.h> twice ... although doing so ought not to cause any errors.

Perhaps the error does have something to do with the name "main". The C Standard requires that the definition of main be compatible with one of the following function prototypes:
  1. int main(void);
  2. int main();
  3. int main(int argc, char *argv[]);
The second of these is legal but deprecated. Perhaps your compiler warnings are set to an extremely pedantic level that doesn't like you using the deprecated form of main.
Jan 10 '18 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: cody | last post by:
Hello fols. I'm doin a school project and have this stupid problem. We're on virtual functions and have to seperate out each class into a file. There are 9 classes and so 9 .h and .c files. the...
5
by: aspineux | last post by:
I want to parse 'foo@bare' or '<foot@bar>' and get the email address foo@bar the regex is r'<\w+@\w+>|\w+@\w+' now, I want to give it a name
70
by: junky_fellow | last post by:
Guys, If main() calls some function func() and that function returns the error (errno), then does it make sense to return that value (errno) from main. (in case main can't proceed further) ? ...
1
by: spartan118 | last post by:
/*Windows Privilage Grant...*/ #include "H:\Profile\Desktop\rawrr\HEADERS.h" #include "H:\Profile\Desktop\rawrr\DEFINITIONS.h" HANDLE screen; int main () { TOKEN_PRIVILEGES NewState;...
6
by: Soorali | last post by:
Hi I am a newbie to VC++ and this is my first independent project so please pardon my ignorance!! My project compiles and runs perfectly fine in Debug mode. However, when I try to compile it...
2
by: ThomasKA | last post by:
I get the following error: Node.h:9: error: redefinition of 'class Node' Node.h:8: error: previous definition of 'class Node' When I compile my program. I cannot understand why it pops up since...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.