-2

Выдает ошибку undefined reference to 'sortirovka', но никак не могу понять, что не так.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define MAX 50

int n; // Кол-во фильмов

struct Buyer // Шаблон структуры { char surname[30]; char name[30]; char middlename[30]; char city[30]; char street[30]; int homenumber; int flatnumber; int creditcard; int purchasecode; };

struct Buyer shopbuyer[MAX];

void menu() { void add(); // Объяление функции add() void search(); // Объяление функции search() void sortirovka(); // Объяление функции sortirovka() void display(); // Объяление функции display() int choice; printf("\tMENU:\n"); printf("1.Add\n"); printf("2.Search\n"); printf("3.Sort\n"); printf("4.Show\n"); printf("5.Exit\n"); printf("Enter choosen position:"); scanf("%d",&choice); switch (choice) { case 1: add(); break; case 2: search(); break; case 3: sortirovka(); break; case 4: display(); break; case 5: exit(0); default: printf("Error. Try again\n"); menu(); }; };

void add() { system("chcp 1251"); system("cls"); // Windows - system("cls"); for (int i = n; i < MAX; i++) { printf("Add new buyer\n"); printf("Surname: "); fgets(shopbuyer[i].surname, 30, stdin); printf("Name: "); fgets(shopbuyer[i].name, 30, stdin); printf("Middle Name: "); fgets(shopbuyer[i].middlename, 30, stdin); printf("City: "); fgets(shopbuyer[i].city, 30, stdin); printf("Street: "); fgets(shopbuyer[i].street, 30, stdin); printf("Home Number: "); scanf("%d",&shopbuyer[i].homenumber); printf("Flat Number: "); scanf("%d",&shopbuyer[i].flatnumber); printf("Credit Card: "); scanf("%d",&shopbuyer[i].creditcard); printf("Purchase Code: "); scanf("%d",&shopbuyer[i].purchasecode); n++; break; }; system("chcp 1251"); system("cls"); menu(); };

void display() { system("chcp 1251"); system("cls"); // Windows - system("cls"); printf("List of Buyers:\n"); for (int i = 0; i < n; i++) { printf("Surname: %s\n", shopbuyer[i].surname); printf("Name: %s\n", shopbuyer[i].name); printf("Middle Name: %s\n", shopbuyer[i].middlename); printf("City: %s\n", shopbuyer[i].city); printf("Street: %s\n", shopbuyer[i].street); printf("Home Number: %d\n", shopbuyer[i].homenumber); printf("Flat Number: %d\n", shopbuyer[i].flatnumber); printf("Credit Card: %d\n", shopbuyer[i].creditcard); printf("Purchase Code: %d\n", shopbuyer[i].purchasecode); printf("\n"); }; menu(); }; // Функция поиска void search() { system("clear"); printf("Enter keyword: "); char keyword[20]; fgets(keyword, 20, stdin);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, &quot;Surname&quot;) == 0) || (strcmp(keyword, &quot;surname&quot;) == 0)) // Если ключевое слово равно title или Title
    {
        char surname2[30];
        printf(&quot;Enter Surname: &quot;);
        fgets(surname2, 30, stdin);
        int c = 0;
        for (int i = 0; i &lt; n; i++)
    { 
        if (strcmp (surname2, shopbuyer[i].surname) == 0) // Проверка на совпадение (0 - совпадение, иначе - 1)
        {
            printf(&quot;Surname: %s&quot;, shopbuyer[i].surname);
            c++;
        };

    };

        if (c == 0) {
            printf(&quot;Not Found&quot;);
        }  // Полная проверка списка title, если совпадений не найдено, вывод - Not found 
    };

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Name&quot;) == 0) || (strcmp(keyword, &quot;name&quot;) == 0)) // 
    {
        char name2[30];
        printf(&quot;Enter Name: &quot;);
        fgets(name2, 30, stdin);
        int c = 0;
        for (int i = 0; i &lt; n; i++)
    { 
        if (strcmp (name2, shopbuyer[i].name) == 0) 
        {
            printf(&quot;Name: %s&quot;, shopbuyer[i].name);
            c++;
        };

    };

        if (c == 0) {
            printf(&quot;Not Found&quot;);
        }  
    };

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Middle Name&quot;) == 0) || (strcmp(keyword, &quot;middle name&quot;) == 0) || (strcmp(keyword, &quot;Middle name&quot;) == 0)) // 
{
    char middlename2[30];
    printf(&quot;Enter Middle Name: &quot;);
    fgets(middlename2, 30, stdin);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
{ 
    if (strcmp (middlename2, shopbuyer[i].middlename) == 0) 
    {
        printf(&quot;Middle Name: %s&quot;, shopbuyer[i].middlename);
        c++;
    };

};

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }  
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;city&quot;) == 0) || (strcmp(keyword, &quot;City&quot;) == 0)) // 
    {
        char city2[30];
        printf(&quot;Enter City: &quot;);
        fgets(city2, 30, stdin);
        int c = 0;
        for (int i = 0; i &lt; n; i++)
    { 
        if (strcmp (city2, shopbuyer[i].city) == 0) 
        {
            printf(&quot;City: %s&quot;, shopbuyer[i].city);
            c++;
        };

    };

        if (c == 0) {
            printf(&quot;Not Found&quot;);
        }  
    };

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Street&quot;) == 0) || (strcmp(keyword, &quot;street&quot;) == 0)) // 
    {
        char street2[30];
        printf(&quot;Enter Street: &quot;);
        fgets(street2, 30, stdin);
        int c = 0;
        for (int i = 0; i &lt; n; i++)
    { 
        if (strcmp (street2, shopbuyer[i].street) == 0) 
        {
            printf(&quot;Street: %s&quot;, shopbuyer[i].street);
            c++;
        };

    };

        if (c == 0) {
            printf(&quot;Not Found&quot;);
        }  
    };

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Home Number&quot;) == 0) || (strcmp(keyword, &quot;Home number&quot;) == 0) || (strcmp(keyword, &quot;home number&quot;) == 0))
{
    int homenumber2;
    printf(&quot;Enter Home Number: &quot;);
    scanf(&quot;%d&quot;,&amp;homenumber2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
{ 
    if (homenumber2 == shopbuyer[i].homenumber)
    {
        printf(&quot;Home Number: %d&quot;, shopbuyer[i].homenumber);
        c++;
    };

};

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }  
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Flat Number&quot;) == 0) || ((strcmp(keyword, &quot;Flat number&quot;) == 0)) || ((strcmp(keyword, &quot;flat number&quot;) == 0))) // 
{
    int flatnumber2;
    printf(&quot;Enter Flat Number: &quot;);
    scanf(&quot;%d&quot;,&amp;flatnumber2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
{ 
    if (flatnumber2 == shopbuyer[i].flatnumber) 
    {
        printf(&quot;Flat Number: %d&quot;, shopbuyer[i].flatnumber);
        c++;
    };

};

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }  
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Credit Card&quot;) == 0) || ((strcmp(keyword, &quot;Credit card&quot;) == 0)) || ((strcmp(keyword, &quot;credit card&quot;) == 0))) // 
{
    int creditcard2;
    printf(&quot;Enter Credit Card: &quot;);
    scanf(&quot;%d&quot;,&amp;creditcard2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
{ 
    if (creditcard2 == shopbuyer[i].creditcard) 
    {
        printf(&quot;Credit Card: %d&quot;, shopbuyer[i].creditcard);
        c++;
    };

};

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }  
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Purchase Code&quot;) == 0) || ((strcmp(keyword, &quot;Purchase code&quot;) == 0)) || ((strcmp(keyword, &quot;purchase Code&quot;) == 0))) // 
{
    int purchasecode2;
    printf(&quot;Enter Purchase Code: &quot;);
    scanf(&quot;%d&quot;,&amp;purchasecode2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
{ 
    if (purchasecode2 == shopbuyer[i].purchasecode) 
    {
        printf(&quot;Purchase Code: %d&quot;, shopbuyer[i].purchasecode);
        c++;
    };

};

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }  
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Функция сортировки пузырьком void sortirovka() { system("chcp 1251"); system("cls"); char keyword[20]; printf("Enter keyword to sort (choose one of them) \n"); printf("Home Number, Flat Number, Credit Card, Purchase Code: "); fgets(keyword, 20, stdin);

//Сортировка по Home_Number if ((strcmp(keyword, "Home Number") == 0) || (strcmp(keyword, "Home number") == 0) || (strcmp(keyword, "home number") == 0)) { for (int i = 0; i < n; i++) { for (int j = n - 1; j >= i; j--) { if (shopbuyer[j-1].homenumber > shopbuyer[j].homenumber) { int temp = 0; temp = shopbuyer[j-1].homenumber; shopbuyer[j-1].homenumber = shopbuyer[j].homenumber; shopbuyer[j].homenumber = temp; }; }; }; };

if ((strcmp(keyword, &quot;Flat Number&quot;) == 0) || (strcmp(keyword, &quot;Flat number&quot;) == 0) || (strcmp(keyword, &quot;flat number&quot;) == 0))
{
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = n - 1; j &gt;= i; j--)
        {
            if (shopbuyer[j-1].flatnumber &gt; shopbuyer[j].flatnumber)
            {
                int temp = 0;
                temp = shopbuyer[j-1].flatnumber;
                shopbuyer[j-1].flatnumber = shopbuyer[j].flatnumber;
                shopbuyer[j].flatnumber = temp;
            };
        };
    };
};

if ((strcmp(keyword, &quot;Credit Card&quot;) == 0) || (strcmp(keyword, &quot;Credit card&quot;) == 0) || (strcmp(keyword, &quot;credit card&quot;) == 0))
{
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = n - 1; j &gt;= i; j--)
        {
            if (shopbuyer[j-1].creditcard &gt; shopbuyer[j].creditcard)
            {
                int temp = 0;
                temp = shopbuyer[j-1].creditcard;
                shopbuyer[j-1].creditcard = shopbuyer[j].creditcard;
                shopbuyer[j].creditcard = temp;
            };
        };
    };
};

if ((strcmp(keyword, &quot;Purchase Code&quot;) == 0) || (strcmp(keyword, &quot;Purchase code&quot;) == 0) || (strcmp(keyword, &quot;purchase code&quot;) == 0))
{
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = n - 1; j &gt;= i; j--)
        {
            if (shopbuyer[j-1].purchasecode &gt; shopbuyer[j].purchasecode)
            {
                int temp = 0;
                temp = shopbuyer[j-1].purchasecode;
                shopbuyer[j-1].purchasecode = shopbuyer[j].purchasecode;
                shopbuyer[j].purchasecode = temp;
            };
        };
    };
};
printf(&quot;Sort complete\n&quot;);
menu();

};

int main() { printf("Enter count of buyers: "); scanf("%d",&n); system("chcp 1251"); system("cls"); for (int i = 0; i < n; i++) { printf("Surname №%d: ", i+1); fgets(shopbuyer[i].surname, 30, stdin); printf("Name №%d: ", i+1); fgets(shopbuyer[i].name, 30, stdin); printf("Middle Name №%d: ", i+1); fgets(shopbuyer[i].middlename, 30, stdin); printf("City №%d: ", i+1); fgets(shopbuyer[i].city, 30, stdin); printf("Street №%d: ", i+1); fgets(shopbuyer[i].street, 30, stdin); printf("Home Number №%d", i+1); scanf("%d", &shopbuyer[i].homenumber); printf("Flat Number №%d", i+1); scanf("%d", &shopbuyer[i].flatnumber); printf("Credit Card №%d", i+1); scanf("%d", &shopbuyer[i].creditcard); printf("Purchase Code №%d", i+1); scanf("%d", &shopbuyer[i].purchasecode); };
menu(); return 0; }}

Ошибки такие:

/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/x86_64-linux-gnu-ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/tmp/ccr8pCVg.o: In function `menu':
main.c:(.text+0x9b): undefined reference to `sortirovka'
collect2: error: ld returned 1 exit status
Daniil Loban
  • 11,208
  • "Выдает ошибку," - какую - не скажете? –  Dec 24 '20 at 19:34
  • Так, да, все, исправил, теперь более понятно должно стать. – Alexey Rutkovsky Dec 24 '20 at 19:37
  • 3
    Что мешает прочитать текст ошибок? Там все написано – Эникейщик Dec 24 '20 at 19:48
  • 1
    Большое спасибо за такой прекрасный комментарий! Вот честно, без вас - никуда – Alexey Rutkovsky Dec 24 '20 at 19:51
  • В 55-й строке программы в первый раз используется переменная shopbuyer, которая не описана ни в этой функции, ни как глобальная во всей программе – avp Dec 24 '20 at 21:12
  • UPD1: Прошлые проблемы решил - появились новые – Alexey Rutkovsky Dec 24 '20 at 21:13
  • 1
    Фигурные скобочки неправильно расставлены (поставьте Emacs и пишите код в нем). 1) Пропущена } , закрывающая функцию void search(); 2) Лишняя } после main() 3) Удалите ; после закрывающих } – avp Dec 24 '20 at 21:28
  • я тоже заметил про скобки но там еще другая ошибка – Daniil Loban Dec 24 '20 at 21:30
  • @DaniilLoban, imho там должно быть полным-полно ошибок – avp Dec 24 '20 at 21:36
  • @avp вполне вероятно, плохо когда не понятно как должно быть по сценарию – Daniil Loban Dec 24 '20 at 21:38
  • Зачем, а главное, ... Вы наставили точек с запятой после каждой фигурной скобки? Функции объявлены все внутри другой функции, хотя должны быть вне её. Выучите хотя бы синтаксис Си для начала. – V-Mor Dec 25 '20 at 02:55
  • Поставьте закрывающую скобку перед определением void sortirovka() (не объявлением, а именно определением). А в самом конце кода уберите. – V-Mor Dec 25 '20 at 02:59

2 Answers2

1

Причина в том что функция search включила в себя все функции до конца файла.

  1. В конце файла нужно убрать одну скобку: 429 cтрока: }

  2. в 316 строке нужно добавить }

В файле желательно поправить все отступы чтобы не появлялись такие ошибки в дальнейшем

...

При вводе одного покупателя начинается цикл и естественно заканчивается ошибкой

введите сюда описание изображения

Daniil Loban
  • 11,208
1

Если брать именно код и ошибку из вопроса и концентрироваться на исправлении именно её, то можно получить вот что: у Вас всего лишь "уехала" фигурная скобка от функции search, в результате чего все остальные функции получились определёнными внутри неё. Делаем вот так и вуаля, решение собирается:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define MAX 50

int n; // Кол-во фильмов

struct Buyer // Шаблон структуры { char surname[30]; char name[30]; char middlename[30]; char city[30]; char street[30]; int homenumber; int flatnumber; int creditcard; int purchasecode; };

struct Buyer shopbuyer[MAX];

void menu() { void add(); // Объяление функции add() void search(); // Объяление функции search() void sortirovka(); // Объяление функции sortirovka() void display(); // Объяление функции display() int choice; printf("\tMENU:\n"); printf("1.Add\n"); printf("2.Search\n"); printf("3.Sort\n"); printf("4.Show\n"); printf("5.Exit\n"); printf("Enter choosen position:"); scanf("%d", &choice); switch (choice) { case 1: add(); break; case 2: search(); break; case 3: sortirovka(); break; case 4: display(); break; case 5: exit(0); default: printf("Error. Try again\n"); menu(); }; };

void add() { system("chcp 1251"); system("cls"); // Windows - system("cls"); for (int i = n; i < MAX; i++) { printf("Add new buyer\n"); printf("Surname: "); fgets(shopbuyer[i].surname, 30, stdin); printf("Name: "); fgets(shopbuyer[i].name, 30, stdin); printf("Middle Name: "); fgets(shopbuyer[i].middlename, 30, stdin); printf("City: "); fgets(shopbuyer[i].city, 30, stdin); printf("Street: "); fgets(shopbuyer[i].street, 30, stdin); printf("Home Number: "); scanf("%d", &shopbuyer[i].homenumber); printf("Flat Number: "); scanf("%d", &shopbuyer[i].flatnumber); printf("Credit Card: "); scanf("%d", &shopbuyer[i].creditcard); printf("Purchase Code: "); scanf("%d", &shopbuyer[i].purchasecode); n++; break; }; system("chcp 1251"); system("cls"); menu(); };

void display() { system("chcp 1251"); system("cls"); // Windows - system("cls"); printf("List of Buyers:\n"); for (int i = 0; i < n; i++) { printf("Surname: %s\n", shopbuyer[i].surname); printf("Name: %s\n", shopbuyer[i].name); printf("Middle Name: %s\n", shopbuyer[i].middlename); printf("City: %s\n", shopbuyer[i].city); printf("Street: %s\n", shopbuyer[i].street); printf("Home Number: %d\n", shopbuyer[i].homenumber); printf("Flat Number: %d\n", shopbuyer[i].flatnumber); printf("Credit Card: %d\n", shopbuyer[i].creditcard); printf("Purchase Code: %d\n", shopbuyer[i].purchasecode); printf("\n"); }; menu(); }; // Функция поиска void search() { system("clear"); printf("Enter keyword: "); char keyword[20]; fgets(keyword, 20, stdin);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, &quot;Surname&quot;) == 0) || (strcmp(keyword, &quot;surname&quot;) == 0)) // Если ключевое слово равно title или Title
{
    char surname2[30];
    printf(&quot;Enter Surname: &quot;);
    fgets(surname2, 30, stdin);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (strcmp(surname2, shopbuyer[i].surname) == 0) // Проверка на совпадение (0 - совпадение, иначе - 1)
        {
            printf(&quot;Surname: %s&quot;, shopbuyer[i].surname);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }  // Полная проверка списка title, если совпадений не найдено, вывод - Not found 
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Name&quot;) == 0) || (strcmp(keyword, &quot;name&quot;) == 0)) // 
{
    char name2[30];
    printf(&quot;Enter Name: &quot;);
    fgets(name2, 30, stdin);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (strcmp(name2, shopbuyer[i].name) == 0)
        {
            printf(&quot;Name: %s&quot;, shopbuyer[i].name);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Middle Name&quot;) == 0) || (strcmp(keyword, &quot;middle name&quot;) == 0) || (strcmp(keyword, &quot;Middle name&quot;) == 0)) // 
{
    char middlename2[30];
    printf(&quot;Enter Middle Name: &quot;);
    fgets(middlename2, 30, stdin);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (strcmp(middlename2, shopbuyer[i].middlename) == 0)
        {
            printf(&quot;Middle Name: %s&quot;, shopbuyer[i].middlename);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;city&quot;) == 0) || (strcmp(keyword, &quot;City&quot;) == 0)) // 
{
    char city2[30];
    printf(&quot;Enter City: &quot;);
    fgets(city2, 30, stdin);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (strcmp(city2, shopbuyer[i].city) == 0)
        {
            printf(&quot;City: %s&quot;, shopbuyer[i].city);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Street&quot;) == 0) || (strcmp(keyword, &quot;street&quot;) == 0)) // 
{
    char street2[30];
    printf(&quot;Enter Street: &quot;);
    fgets(street2, 30, stdin);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (strcmp(street2, shopbuyer[i].street) == 0)
        {
            printf(&quot;Street: %s&quot;, shopbuyer[i].street);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Home Number&quot;) == 0) || (strcmp(keyword, &quot;Home number&quot;) == 0) || (strcmp(keyword, &quot;home number&quot;) == 0))
{
    int homenumber2;
    printf(&quot;Enter Home Number: &quot;);
    scanf(&quot;%d&quot;, &amp;homenumber2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (homenumber2 == shopbuyer[i].homenumber)
        {
            printf(&quot;Home Number: %d&quot;, shopbuyer[i].homenumber);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Flat Number&quot;) == 0) || ((strcmp(keyword, &quot;Flat number&quot;) == 0)) || ((strcmp(keyword, &quot;flat number&quot;) == 0))) // 
{
    int flatnumber2;
    printf(&quot;Enter Flat Number: &quot;);
    scanf(&quot;%d&quot;, &amp;flatnumber2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (flatnumber2 == shopbuyer[i].flatnumber)
        {
            printf(&quot;Flat Number: %d&quot;, shopbuyer[i].flatnumber);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Credit Card&quot;) == 0) || ((strcmp(keyword, &quot;Credit card&quot;) == 0)) || ((strcmp(keyword, &quot;credit card&quot;) == 0))) // 
{
    int creditcard2;
    printf(&quot;Enter Credit Card: &quot;);
    scanf(&quot;%d&quot;, &amp;creditcard2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (creditcard2 == shopbuyer[i].creditcard)
        {
            printf(&quot;Credit Card: %d&quot;, shopbuyer[i].creditcard);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((strcmp(keyword, &quot;Purchase Code&quot;) == 0) || ((strcmp(keyword, &quot;Purchase code&quot;) == 0)) || ((strcmp(keyword, &quot;purchase Code&quot;) == 0))) // 
{
    int purchasecode2;
    printf(&quot;Enter Purchase Code: &quot;);
    scanf(&quot;%d&quot;, &amp;purchasecode2);
    int c = 0;
    for (int i = 0; i &lt; n; i++)
    {
        if (purchasecode2 == shopbuyer[i].purchasecode)
        {
            printf(&quot;Purchase Code: %d&quot;, shopbuyer[i].purchasecode);
            c++;
        };

    };

    if (c == 0) {
        printf(&quot;Not Found&quot;);
    }
};

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Функция сортировки пузырьком void sortirovka() { system("chcp 1251"); system("cls"); char keyword[20]; printf("Enter keyword to sort (choose one of them) \n"); printf("Home Number, Flat Number, Credit Card, Purchase Code: "); fgets(keyword, 20, stdin);

//Сортировка по Home_Number
if ((strcmp(keyword, &quot;Home Number&quot;) == 0) || (strcmp(keyword, &quot;Home number&quot;) == 0) || (strcmp(keyword, &quot;home number&quot;) == 0))
{
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = n - 1; j &gt;= i; j--)
        {
            if (shopbuyer[j - 1].homenumber &gt; shopbuyer[j].homenumber)
            {
                int temp = 0;
                temp = shopbuyer[j - 1].homenumber;
                shopbuyer[j - 1].homenumber = shopbuyer[j].homenumber;
                shopbuyer[j].homenumber = temp;
            };
        };
    };
};

if ((strcmp(keyword, &quot;Flat Number&quot;) == 0) || (strcmp(keyword, &quot;Flat number&quot;) == 0) || (strcmp(keyword, &quot;flat number&quot;) == 0))
{
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = n - 1; j &gt;= i; j--)
        {
            if (shopbuyer[j - 1].flatnumber &gt; shopbuyer[j].flatnumber)
            {
                int temp = 0;
                temp = shopbuyer[j - 1].flatnumber;
                shopbuyer[j - 1].flatnumber = shopbuyer[j].flatnumber;
                shopbuyer[j].flatnumber = temp;
            };
        };
    };
};

if ((strcmp(keyword, &quot;Credit Card&quot;) == 0) || (strcmp(keyword, &quot;Credit card&quot;) == 0) || (strcmp(keyword, &quot;credit card&quot;) == 0))
{
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = n - 1; j &gt;= i; j--)
        {
            if (shopbuyer[j - 1].creditcard &gt; shopbuyer[j].creditcard)
            {
                int temp = 0;
                temp = shopbuyer[j - 1].creditcard;
                shopbuyer[j - 1].creditcard = shopbuyer[j].creditcard;
                shopbuyer[j].creditcard = temp;
            };
        };
    };
};

if ((strcmp(keyword, &quot;Purchase Code&quot;) == 0) || (strcmp(keyword, &quot;Purchase code&quot;) == 0) || (strcmp(keyword, &quot;purchase code&quot;) == 0))
{
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = n - 1; j &gt;= i; j--)
        {
            if (shopbuyer[j - 1].purchasecode &gt; shopbuyer[j].purchasecode)
            {
                int temp = 0;
                temp = shopbuyer[j - 1].purchasecode;
                shopbuyer[j - 1].purchasecode = shopbuyer[j].purchasecode;
                shopbuyer[j].purchasecode = temp;
            };
        };
    };
};
printf(&quot;Sort complete\n&quot;);
menu();

};

int main() { printf("Enter count of buyers: "); scanf("%d", &n); system("chcp 1251"); system("cls"); for (int i = 0; i < n; i++) { printf("Surname №%d: ", i + 1); fgets(shopbuyer[i].surname, 30, stdin); printf("Name №%d: ", i + 1); fgets(shopbuyer[i].name, 30, stdin); printf("Middle Name №%d: ", i + 1); fgets(shopbuyer[i].middlename, 30, stdin); printf("City №%d: ", i + 1); fgets(shopbuyer[i].city, 30, stdin); printf("Street №%d: ", i + 1); fgets(shopbuyer[i].street, 30, stdin); printf("Home Number №%d", i + 1); scanf("%d", &shopbuyer[i].homenumber); printf("Flat Number №%d", i + 1); scanf("%d", &shopbuyer[i].flatnumber); printf("Credit Card №%d", i + 1); scanf("%d", &shopbuyer[i].creditcard); printf("Purchase Code №%d", i + 1); scanf("%d", &shopbuyer[i].purchasecode); }; menu(); return 0; }

Корректность работы самой программы не проверял, но, как я понял, проблема была именно при сборке и я её решил.

V-Mor
  • 5,127