Hello,
Could someone tell me what i am doing wrong?
The code compiles and runs perfectly on my system, but when i upload it here, it gives a [color=#FF0000]SIGABRT Runtime Error[/color]
Some guidance will be deeply appreciated... Thanks !
#include<iostream>
#include<vector>
#include<cctype>
using namespace std;
int is_cpp_identifier(string);
string convert_to_cpp(string);
string convert_to_java(string);
void display (vector<string> v)
{
vector<string>::iterator it;
for(it=v.begin();it!=v.end();++it)
{
cout<<*it<<endl;
}
cout<<endl;
}
int main()
{
vector<string> ids;
vector<string>::iterator it;
string temp;
cin>>temp;
ids.push_back(temp);
while(!cin.eof())
{
cin>>temp;
ids.push_back(temp);
}
// display(ids);
for(it=ids.begin(); it!=ids.end(); ++it)
{
switch( is_cpp_identifier(*it) )
{
case 0 : cout<<convert_to_cpp(*it)<<endl;
break;
case 1 : cout<<convert_to_java(*it)<<endl;
break;
case 2 : cout<<*it<<endl;
break;
default : cout<<"Error!"<<endl;
}
}
}
int is_cpp_identifier(string s)
{
size_t i;
for(i=0; i<s.length(); ++i)
{
if(s.at(i)=='_') // if underscore is found -> c++ identifier
{
if(islower(s.at(i+1)))
return 1;
else
return 601;
}
else if(isupper(s.at(i))) // else if a capital letter -> java identifier
{
while(i<s.length() && isalpha(s.at(i++)));
if(i==s.length())
return 0;
else
return 600;
}
}
return 2; // else it is common identifier
}
string convert_to_cpp(string s)
{
size_t i;
string temp="_#"; // make a temporary string
for(i=0; i<s.length(); ++i)
{
if(isupper(s.at(i))) // if capital letter is found
{
temp[1] = tolower(s.at(i));
s.replace(i,1,temp); // replace 'X' with '_x'
}
}
return s;
}
string convert_to_java(string s)
{
size_t i;
string temp="#"; // make a temporary string
for(i=0; i<s.length(); ++i)
{
if(s.at(i)=='_') // if underscore is found
{
temp[0] = toupper(s.at(i+1));
s.replace(i,2,temp); // replace '_x' with 'X'
}
}
return s;
}