Как присвоить значения указателя элемента структуры друг другу? - PullRequest
1 голос
/ 12 февраля 2020

Я пытаюсь внедрить BubbleSort-Algorithm в мою C -Программу для сортировки элементов структур (например, по элементам «name») внутри двусвязного списка, содержащего записи игр, которые мне нравятся. Когда я пытаюсь присвоить элемент другому того же типа, я получаю это сообщение об ошибке:

[Ошибка] присваивание выражению с типом массива

Здесь соответствующая часть моего кода:

typedef struct game {
    char name[50];
    float price;
    int release;
    char genre[30];
    struct game *next; /*points to the next structure and to NULL if it's the last one*/
    struct game *prev; /*points to the previous structure and to NULL if it's the first one*/
}game;

typedef struct {
    struct game *first; /*points to the first element*/
    struct game *now; /*points to the element currently viewed*/
    struct game *last; /*points to the last element*/
}s_field;

void swap(s_field *lib) {
    char *tempName;
    tempName = lib->now->name;
    lib->now->name = lib->now->next->name; /*This is the line where I first get the error*/
    lib->now->next->name = tempName;
    /*There are assignments like those above for every other variable here*/
}

swap (s_field * lib) выполняется внутри функции main. Есть ли способ обойти эту проблему? Например, каким-нибудь типом передачи?

...