so i have this code in which i need to input some data and then the program need to put the data in alphabetical order
the problem is that i cant convert string name to char s1 and s2.
DATA to input:
https://pastebin.com/BvMQANpg
#include <iostream>
#include <string>
using namespace std;
struct obiectiv {
int id;
string name;
double latitud;
double longitud;
double cost_vizitare;
};
int main()
{
int i, k, temp;
struct obiectiv ob[9];
cout << "Introduceti obiectivele(maxim 9): ID NAME LATITUD LONGITUD PRICE" << endl;
for (i = 0; i < 9; i++) {
cin >> ob[i].id >> ob[i].name >> ob[i].latitud >> ob[i].longitud >> ob[i].cost_vizitare;
}
struct obiectiv tempob[9];
struct obiectiv t[9];
for (i = 0;i < 9;i++) {
tempob[i] = ob[i];
}
int sorted;
for (k = 0; k < 9;k++) {
sorted = 1;
for (i = 0;i < 9;i++) {
char* s1 = tempob[i].name;
char* s2 = tempob[i + 1].name;
if (strcmp(s1,s2) > 0) {
t[i] = ob[i];
tempob[i] = tempob[i + 1];
tempob[i + 1] = t[i];
sorted = 0;
}
}
if (sorted == 1) {
break;
}
}
cout << "alphabetical order: ";
for (i = 0;i < 9;i++) {
cout << tempob[i].name << endl;
}
}
Source: Windows Questions C++