Сортировка структуры по полю char - C (СИ)
Формулировка задачи:
Есть структура
Нужно отсортировать ее
Делаю сортировку
Проблем не возникает сортировать интовские поля а как чаровские поля сортировать air[j].destination и air[i].tip просто вылазиет ошибка у меня
и так 6 раз
обьявляю так
Как исправить?
struct AeroFlot
{
char* destination[50];
char* tip[50];
int nomer;
int zanmest;
int svobmest;
};for(i=0;i<n;i++)
{
for(int j = 0 ; j < n - i - 1 ; j++)
{
if(air[j].svobmest>air[j+1].svobmest)
{
tmp1=air[j].nomer;
tmp4=air[j].destination;
tmp5=air[i].tip;
tmp2=air[j].svobmest;
tmp3=air[j].zanmest;
air[j].nomer=air[j+1].nomer;
air[j].destination=air[j+1].destination;
air[j].tip=air[j+1].tip;
air[j].svobmest=air[j+1].svobmest;
air[j].zanmest=air[j+1].zanmest;
air[j+1].nomer=tmp1;
air[j+1].destination=tmp4;
air[j+1].tip=tmp5;
air[j+1].svobmest=tmp2;
air[j+1].zanmest=tmp3;
}
}
}ISO C++ forbids assignment of arrays
int tmp1,tmp2,tmp3;
char *tmp4[50];
char *tmp5[50];Решение задачи: «Сортировка структуры по полю char»
textual
Листинг программы
#include "stdafx.h"
#include <iostream>
struct AeroFlot
{
char* destination[50];
char* tip[50];
int nomer;
int zanmest;
int svobmest;
};
int main(){
struct AeroFlot a;
struct AeroFlot b;
a.nomer=1;
b=a;
std::cin>>b.svobmest;
a=b;
return 0;
}