Doubt of solution

Can you find segmentational error in below code(solution for day 9 sort the strings problem).

#include
#include
using namespace std;
string extractKey(string str, int key)
{
char *s = strtok((char *)str.c_str(), " ");
while (key > 1)
{
s = strtok(NULL, " ");
key–;
}
return (string)s;
}
int convertToint(string str)
{
int p = 1;
int ans = 0;
for (int i = str.length(); i >= 0; i++)
{
ans += (str[i] - ‘0’) * p;
p *= 10;
}
return ans;
}
bool lexicoCompare(pair<string, string> s1, pair<string, string> s2)
{
string key1 = s1.second;
string key2 = s2.second;
return (key1 < key2);
}
bool numericCompare(pair<string, string> s1, pair<string, string> s2)
{
string key1 = s1.second;
string key2 = s2.second;
return convertToint(key1) <
convertToint(key2);
}

int main()
{
int n;
cin>>n;
cin.get();
string a[100];
pair<string, string> strPair[100];
for (int j = 0; j < n; j++)
{
getline(cin, a[j]);
}
int key;
string reversal, ordering;
cin >> key >> reversal >> ordering;
for (int i = 0; i < n; i++)
{
strPair[i].first = a[i];
strPair[i].second = extractKey(a[i], key);
}

if (ordering == "lexicographical")
{
	sort(strPair, strPair + n, lexicoCompare);
}
else
{

sort(strPair, strPair + n, numericCompare);
}
if (reversal == “true”)
{
for(int i=0;i<n/2;i++){
swap(strPair[i],strPair[n-i-1]);
}
}
for (int i = 0; i < n; i++)
{
cout << strPair[i].first << " "<< endl;
}
return 0;
}