multiple definition of `main'

chauhanshiksha1 (2)
Hi,
I am working in topcoders arena an am getting the error

Your code did not compile:

errors linking:

NameSort-stub.o(.text+0x750): In function `main':
: multiple definition of `main'
NameSort.o(.text+0x514): first defined here
/usr/bin/ld: Warning: size of symbol `main' changed from 1811 in NameSort.o to 1881 in NameSort-stub.o
collect2: ld returned 1 exit status


My code is below..
please help regarding the problem..


#include<functional>
#include<cstdio>
//#include<conio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
//#include<process>

using namespace std;
void stoupper(std::string& s)
{
string::iterator i = s.begin();
string::iterator end = s.end();

while (i != end) {
*i = toupper((unsigned char)*i);
++i;
}

cout<<s<<endl;
}
bool criteria(string a,string b)
{
//char *i,*j;
//cout<<"here5";
size_t i=a.rfind(" ");
size_t j=b.rfind(" ");
//cout<<"here3";
string m,n;
if(i==a.length())
{
m=a;
}else
m.assign(a,i+1,a.length());
if(j==b.length())
{
n=b;
}else
n.assign(b,j+1,b.length());
stoupper(m);
stoupper(n);
int l=m.compare(n);
if(l<=0)
return 1;
else
return 0;
}
class NameSort{
public:
vector<string> newList(vector<string> list)
{//cout<<"here1";
sort(list.begin(), list.end(),criteria );
//cout<<"here2";
return list;
}
};
int main()
{
int x;
cout<<"enter the no of members";
cin>>x;
if(x>50 ||x<1)
{
cout<<"not possible,exiting";
exit(2);
}
// getch();
vector<string> v1,v2;
string str[50],q;
int i;
getline(cin,q);
for(i=0;i<x;i++)
{//cout<<"input";
z: getline(cin,str[i]);
int p=str[i].length();
//cout<<"here";
if(p>20||p<1||str[i].at(0)==' '||str[i].at(p-1)==' ')
{
cout<<"not permitted,input again";
goto z;
}
//cout<<"here";
for(int j=0;j<str[i].length();j++)
{ //cout<<"here1";
if(!((str[i].at(j)>='A'&&str[i].at(j)<='Z')||(str[i].at(j)>='a'&&str[i].at(j)<='z')||str[i].at(j)==' '))
{
cout<<"not permitted,input again";
goto z;
}
//cout<<"here2";
if(str[i].at(j)==' '&&str[i].at(j-1)==' ')
{
cout<<"not permitted,input again";
goto z;
}
}
v2.push_back(str[i]);
//cout<<endl<<"done";
}
//for(i=0;i<v2.size();i++)
//cout<<v2[i];


NameSort ns;
v1=ns.newList(v2);
for(i=0;i<x;i++)
{cout<<endl<<v1.at(i);}
getchar();
return 0;
}

Thanx in advance or any help i receive. :) :)
kev82 (319)
Have you tried asking on the TopCoder forums?

Last time I competed, you couldn't include main functions in your source code. The TopCoder system automatically instantiated/invoked your class.
TheIdeasMan (1564)
Apart from other problems, there are improvements that could be made to your code.

Please edit your post so it uses the code tags - select the code then press the <> button on the right.

So it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for(int j=0;j<str[i].length();j++)
{ //cout<<"here1";
if(!((str[i].at(j)>='A'&&str[i].at(j)<='Z')||(str[i].at(j)>='a'&&str[i].at(j)<='z')||str[i].at(j)==' '))
{
cout<<"not permitted,input again";
goto z;
}
//cout<<"here2";
if(str[i].at(j)==' '&&str[i].at(j-1)==' ')
{
cout<<"not permitted,input again";
goto z;
}
}
v2.push_back(str[i]);
//cout<<endl<<"done";
}
//for(i=0;i<v2.size();i++)
//cout<<v2[i]; 


DO NOT USE GOTO
There are situations where this is valid, but this is not one of them. Always use a loop or functions to achieve what you want. Don't be tempted to use infinite loops either - have a proper exit condition for your loop.

Once I see all you r code formatted properly I (& others) might have further help.

Some proper indenting would be good too - should be easy if you are using an IDE or half decent editor.
Last edited on
chauhanshiksha1 (2)
It worked..
Thanks...
Registered users can post here. Sign in or register to post.