![]() |
| | #1 |
| Registered User Join Date: Sep 2003
Posts: 21
| Main Declaration error So I was on the FAQ page (yes sometimes newbie's actually read it!!) to learn more about the main declarations...specifically the below thread.http://faq.cprogramming.com/cgi-bin/...&id=1043284376 So for C++ I put down:- Code: int main(int argc, char *argv[]) Code: warning C4508: 'main' : function should return a value; 'void' return type assumed Code: return 1; Code:
warning C4508: 'main' : function should return a value; 'void' return type assumed
error C2562: 'main' : 'void' function returning a value
see declaration of 'main'
Cheers Starkhorn |
| starkhorn is offline | |
| | #2 |
| vae victus! Join Date: Nov 2003
Posts: 594
| I'm not sure what is wrong, but out of curiosity does it result in the same warning and error if you declare main as such: Code: int main(void){return 0;}
|
| skorman00 is offline | |
| | #3 |
| Registered User Join Date: Sep 2003
Posts: 21
| having a program with just that 1 line obviously worked fine. But when I changed my own program to match that, I got the exact same warning and error. I've double-checked to ensure that I've not got any mis-placed curley brackets or anything and all seems fine. Cheers Starkhorn |
| starkhorn is offline | |
| | #4 |
| vae victus! Join Date: Nov 2003
Posts: 594
| that's very odd...would you mind posting your entire main.cpp, or whatever you have it called? |
| skorman00 is offline | |
| | #5 |
| Registered User Join Date: Sep 2003
Posts: 21
| Here you go. Sorry if it's too long and thanks for taking the time to help. Code: #include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
#define GameNo_String "<GameNo"
#define TurnNo_String "<TurnNo"
#define NationNo_String "<NationNo"
#define Name_String "<Name"
#define Artifact_string "<Artifact"
#define Char_End_string "</Character"
#define NUM_OF_ARTIFACTS 6
#define NUM_OF_CHARS 21
typedef struct
{
int id, location;
}ARTIFACTS;
typedef struct
{
string name;
int location;
ARTIFACTS arti_list[NUM_OF_ARTIFACTS];
}CHARACTER;
int StringToInt(const string &s)
{
int i;
istringstream myStream(s);
if (myStream>>i)
return i;
else
return 0;
}
int compare_string(string str1, string str2)
{
if (str1 == str2)
return 1;
else
return 0;
}
int get_info(ifstream &finput,string str, int &i)
{
getline(finput,str,'<');
i++;
return StringToInt(str);
}
int main(int argc, char *argv[])
{
ifstream fin;
ofstream fout;
string szLine = "";
int game_num = 0, turn_num = 0, nation_num = 0, compare_string_choice = 0;
CHARACTER char_list[NUM_OF_CHARS];
fin.open("test.xml");
if(fin.fail())
{
cout << "ERROR\n";
return;
}
fout.open("out_test.xml");
if (fout.fail())
{
cout << "ERROR output";
return;
}
while (!fin.eof())
{
getline(fin,szLine,'>');
switch(compare_string_choice)
{
case 0:
if (compare_string(szLine,GameNo_String))
{
game_num=(get_info(fin,szLine,compare_string_choice));
cout << "Game number:- " << game_num << endl;
}
break;
case 1:
if (compare_string(szLine,TurnNo_String))
{
turn_num=(get_info(fin,szLine,compare_string_choice));
cout << "Turn number:- " << turn_num << endl;
}
break;
case 2:
if (compare_string(szLine,NationNo_String))
{
nation_num=(get_info(fin,szLine,compare_string_choice));
cout << "Nation number:- " << nation_num << endl;
}
break;
default:
break;
}
}
fout.close();
fin.close();
// cout << "The number of argc elements are " << argc << endl;
// cout << "The location of the program is " << argv[0] << endl << endl;
return 1;
}
|
| starkhorn is offline | |
| | #6 |
| vae victus! Join Date: Nov 2003
Posts: 594
| I'm sorry sir, but I am completely clueless. Some of your stuff is a little "old style" but is by no means wrong, nor should it cause such an error. All I can say is something may be wrong with your projects settings...that error sounds more like something you'd get from a C compiler rather than a C++ compiler. I doubt it would be getting confused on how to compile, because it would scream about iostream and the other headers. Hopefully somebody else can help you out. |
| skorman00 is offline | |
| | #7 |
| Registered User Join Date: Sep 2003
Posts: 21
| ok thanks. I'll check out the project settings.....it seems VC++6.0 seems to make things 50 times harder than it needs to be but...... ![]() Just curious now, which parts are "old style" ? I hadn't really realised that there was a new or old style.....I guess I'm showing my age there now. ![]() Cheers Starkhorn |
| starkhorn is offline | |
| | #8 |
| Anti-Poster Join Date: Feb 2002
Posts: 1,212
| I'll admit I had no idea what was going on until I tried to compile your code. The problem lies on lines with a return statement but that don't return a value. This happens in both of your if statements when checking for a failed file opening. Add a return value on these lines, and it's fixed.
__________________ Rule #1: Every rule has exceptions Traveller's Dilemma Contest Site - Results posted! |
| pianorain is offline | |
| | #9 |
| and the hat of marbles Join Date: May 2002 Location: Göteborg, Sweden
Posts: 2,038
| Wow, that was one really cryptic error message! Points to VC++ 6! (good job pianorain)
__________________ Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling |
| Sang-drax is offline | |
| | #10 |
| Registered User Join Date: Sep 2003
Posts: 21
| ahhh ok, thank you pianorain...it's so obvious when someone else tells you the answer. ![]() Seriously thank you....I was totally being confused by the conflicting error messages. Cheers Starkhorn |
| starkhorn is offline | |
| | #11 | |
| C/C++Newbie Join Date: May 2005
Posts: 210
| Quote:
| |
| Antigloss is offline | |
| | #12 |
| Registered User Join Date: May 2002
Posts: 41
| title You really should not use main() to call stuff. Use another function for that. And it's best to always have main at the beginning before any other funcitons.
__________________ Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C |
| smog890 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to monitor process creation? | markiz | Windows Programming | 31 | 03-17-2008 02:39 PM |
| more then 100errors in header | hallo007 | Windows Programming | 20 | 05-13-2007 08:26 AM |
| We Got _DEBUG Errors | Tonto | Windows Programming | 5 | 12-22-2006 05:45 PM |
| Connecting to a mysql server and querying problem | Diod | C++ Programming | 8 | 02-13-2006 10:33 AM |
| using c++ in c code | hannibar | C Programming | 17 | 10-28-2005 09:09 PM |