Выдает ошибку 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, "Surname") == 0) || (strcmp(keyword, "surname") == 0)) // Если ключевое слово равно title или Title
{
char surname2[30];
printf("Enter Surname: ");
fgets(surname2, 30, stdin);
int c = 0;
for (int i = 0; i < n; i++)
{
if (strcmp (surname2, shopbuyer[i].surname) == 0) // Проверка на совпадение (0 - совпадение, иначе - 1)
{
printf("Surname: %s", shopbuyer[i].surname);
c++;
};
};
if (c == 0) {
printf("Not Found");
} // Полная проверка списка title, если совпадений не найдено, вывод - Not found
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "Name") == 0) || (strcmp(keyword, "name") == 0)) //
{
char name2[30];
printf("Enter Name: ");
fgets(name2, 30, stdin);
int c = 0;
for (int i = 0; i < n; i++)
{
if (strcmp (name2, shopbuyer[i].name) == 0)
{
printf("Name: %s", shopbuyer[i].name);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "Middle Name") == 0) || (strcmp(keyword, "middle name") == 0) || (strcmp(keyword, "Middle name") == 0)) //
{
char middlename2[30];
printf("Enter Middle Name: ");
fgets(middlename2, 30, stdin);
int c = 0;
for (int i = 0; i < n; i++)
{
if (strcmp (middlename2, shopbuyer[i].middlename) == 0)
{
printf("Middle Name: %s", shopbuyer[i].middlename);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "city") == 0) || (strcmp(keyword, "City") == 0)) //
{
char city2[30];
printf("Enter City: ");
fgets(city2, 30, stdin);
int c = 0;
for (int i = 0; i < n; i++)
{
if (strcmp (city2, shopbuyer[i].city) == 0)
{
printf("City: %s", shopbuyer[i].city);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "Street") == 0) || (strcmp(keyword, "street") == 0)) //
{
char street2[30];
printf("Enter Street: ");
fgets(street2, 30, stdin);
int c = 0;
for (int i = 0; i < n; i++)
{
if (strcmp (street2, shopbuyer[i].street) == 0)
{
printf("Street: %s", shopbuyer[i].street);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "Home Number") == 0) || (strcmp(keyword, "Home number") == 0) || (strcmp(keyword, "home number") == 0))
{
int homenumber2;
printf("Enter Home Number: ");
scanf("%d",&homenumber2);
int c = 0;
for (int i = 0; i < n; i++)
{
if (homenumber2 == shopbuyer[i].homenumber)
{
printf("Home Number: %d", shopbuyer[i].homenumber);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "Flat Number") == 0) || ((strcmp(keyword, "Flat number") == 0)) || ((strcmp(keyword, "flat number") == 0))) //
{
int flatnumber2;
printf("Enter Flat Number: ");
scanf("%d",&flatnumber2);
int c = 0;
for (int i = 0; i < n; i++)
{
if (flatnumber2 == shopbuyer[i].flatnumber)
{
printf("Flat Number: %d", shopbuyer[i].flatnumber);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "Credit Card") == 0) || ((strcmp(keyword, "Credit card") == 0)) || ((strcmp(keyword, "credit card") == 0))) //
{
int creditcard2;
printf("Enter Credit Card: ");
scanf("%d",&creditcard2);
int c = 0;
for (int i = 0; i < n; i++)
{
if (creditcard2 == shopbuyer[i].creditcard)
{
printf("Credit Card: %d", shopbuyer[i].creditcard);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ((strcmp(keyword, "Purchase Code") == 0) || ((strcmp(keyword, "Purchase code") == 0)) || ((strcmp(keyword, "purchase Code") == 0))) //
{
int purchasecode2;
printf("Enter Purchase Code: ");
scanf("%d",&purchasecode2);
int c = 0;
for (int i = 0; i < n; i++)
{
if (purchasecode2 == shopbuyer[i].purchasecode)
{
printf("Purchase Code: %d", shopbuyer[i].purchasecode);
c++;
};
};
if (c == 0) {
printf("Not Found");
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Функция сортировки пузырьком
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, "Flat Number") == 0) || (strcmp(keyword, "Flat number") == 0) || (strcmp(keyword, "flat number") == 0))
{
for (int i = 0; i < n; i++)
{
for (int j = n - 1; j >= i; j--)
{
if (shopbuyer[j-1].flatnumber > 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, "Credit Card") == 0) || (strcmp(keyword, "Credit card") == 0) || (strcmp(keyword, "credit card") == 0))
{
for (int i = 0; i < n; i++)
{
for (int j = n - 1; j >= i; j--)
{
if (shopbuyer[j-1].creditcard > 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, "Purchase Code") == 0) || (strcmp(keyword, "Purchase code") == 0) || (strcmp(keyword, "purchase code") == 0))
{
for (int i = 0; i < n; i++)
{
for (int j = n - 1; j >= i; j--)
{
if (shopbuyer[j-1].purchasecode > shopbuyer[j].purchasecode)
{
int temp = 0;
temp = shopbuyer[j-1].purchasecode;
shopbuyer[j-1].purchasecode = shopbuyer[j].purchasecode;
shopbuyer[j].purchasecode = temp;
};
};
};
};
printf("Sort complete\n");
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

shopbuyer, которая не описана ни в этой функции, ни как глобальная во всей программе – avp Dec 24 '20 at 21:12}, закрывающая функциюvoid search(); 2) Лишняя}послеmain()3) Удалите;после закрывающих}– avp Dec 24 '20 at 21:28void sortirovka()(не объявлением, а именно определением). А в самом конце кода уберите. – V-Mor Dec 25 '20 at 02:59