I don't understand what my compiler doesn't like. Syntax seems to be all right. Please help me, an incompetent person, find what the error is. The header file is:

#ifndef ADD_H #define ADD_H int add(int &num, struct system *base); #endif 

 #include "add.h" #include <stdio.h> #include <string.h> int add(int &num, struct system *base) { int new = num; printf("Номер видеокасеты: "); scanf("%d", &base[num].number); printf("Название фильма: "); scanf("%s", base[num].name); printf("Страна, где был снят фильм: "); scanf("%s", base[num].country); printf("Продолжительность фильма: "); scanf("%d", &base[num].span); printf("Жанр фильма; "); scanf("%s", base[num].genre); printf("Дата приобретения касеты(через пробел): "); printf("День Месяц Год"); scanf("%d %d %d", &base[num].day, &base[num].mounth, &base[num].year); num++; if(num == new + 1) printf("\nOK!\n"); else printf("\nError\n"); return new; } 

 int main() { struct system base[100]; int num = 0; char name_file[40] = "export.txt"; name_file; int key = 0; while (1) { key = menu(); switch (key) { case 1: add(num, base); break; case 2: clear(num, base); break; default: printf("Error! \n"); break; } } } 

Displays by mistake in these 2 modules.

clear.h

 #ifndef CLEAR_H #define CLEAR_H int clear(int *num, system *base ); #endif 

add.h

 #ifndef ADD_H #define ADD_H int add(int *num, system *base ); #endif 

There are still 2 errors left ...

 cd '/Users/gorbunov/Downloads/Программы/my_kursach' /usr/bin/make -f Makefile CONF=Debug "/Library/Developer/CommandLineTools/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf "/Library/Developer/CommandLineTools/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/my_kursach mkdir -p build/Debug/GNU-MacOSX rm -f "build/Debug/GNU-MacOSX/main.od" gcc -c -g -MMD -MP -MF "build/Debug/GNU-MacOSX/main.od" -o build/Debug/GNU-MacOSX/main.o main.c In file included from main.c:3: ./add.h:3:19: error: unknown type name 'system' int add(int *num, system *base); ^ In file included from main.c:4: ./clear.h:3:21: error: unknown type name 'system' int clear(int *num, system *base ); ^ main.c:11:5: warning: expression result unused [-Wunused-value] name_file; ^~~~~~~~~ 1 warning and 2 errors generated. make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 СОБРАТЬ FAILED (значение выхода 2,, общее время: 375ms) 
  • Add code instead of a picture and correct the format. - 0xdb
  • Is that how it goes? - Vladislav
  • @ 0xdb, oh-pa, why didn't I get warned about the presence of edits in the queue when I made mine? - ߊߚߤߘ
  • Judging by the fact that you pass the argument by reference, you use the C ++ compiler. But in C ++, the word new is key. Perhaps this is the problem. - pank
  • one
    @ Vladislav If you write on si, then what does int &num mean? - 0xdb

2 answers 2

The compiler at you swears (same C) on transfer of argument according to the link

 int add(int &num, struct system *base) ^ - вот этого C не умеет 

It is necessary so:

 int add(int *num, struct system *base) { int new = *num; printf("Номер видеокасеты: "); scanf("%d", &base[new].number); ... (*num)++; ... 

Update

See, in main.h do this:

 typedef struct system_{ char name[50]; char country[50]; char genre[50]; int span; int day; int number; int mounth; int year; } system; 

and in add.c -

 int add(int *num, system *base) { int mem = *num; printf("Номер видеокасеты: "); scanf("%d", &base[*num].number); printf("Название фильма: "); scanf("%s", base[*num].name); printf("Страна, где был снят фильм: "); scanf("%s", base[*num].country); printf("Продолжительность фильма: "); scanf("%d", &base[*num].span); printf("Жанр фильма; "); scanf("%s", base[*num].genre); printf("Дата приобретения касеты(через пробел): "); printf("День Месяц Год"); scanf("%d %d %d", &base[*num].day, &base[*num].mounth, &base[*num].year); (*num)++; if(*num == mem + 1) printf("\nOK!\n"); else printf("\nError\n"); return mem; } 

Either merge all the h-files into one, or everywhere first turn on main.h - because the type of structure is declared in it!

clear.c should look like

 #include "main.h" #include "clear.h" #include <stdio.h> #include <string.h> int clear(int *num, system *base ) { char name[50]; printf("Введите номер видеоксеты: "); scanf("%d", name); int sur = *num; for(int i=0; i<*num; i++) { if(strcmp(name, base[i].number)==0) { for(int j = i; j< *num - 1; j++) { strcpy(base[j].number, base[j+1].number); strcpy(base[j].name, base[j+1].name); strcpy(base[j].country, base[j+1].country); strcpy(base[j].genre, base[j+1].genre); strcpy(base[j].span, base[j+1].span); base[j].day = base[j+1].day; base[j].mounth = base[j+1].mounth; base[j].year = base[j+1].year; } (*num)--; if(*num == sur - 1) printf("OK!\n"); else printf("Error!\n"); } } return *num; } 

In menu.c remove the angle brackets in the menu.h include, replace with quotes, and include stdio.h

main.c should look like

 #include <stdio.h> #include "main.h" #include "menu.h" #include "add.h" #include "clear.h" int main() { system base[100]; int num = 0; char name_file[40] = "export.txt"; name_file; int key = 0; while (1) { key = menu(); switch (key) { case 1: add(&num, base); break; case 2: clear(&num, base); break; default: printf("Error! \n"); break; } } } 

LOGIC NOT CHECKED , just sought to compile.

Excuse me, but the feeling that this is your first program, and you didn’t take the book in your hands! ...

  • She's in my main. Look, I added the code - Vladislav
  • @ Vladislav the compiler tried, as he could, to parse the syntactically incorrect code. Start by getting rid of &num , some of the problems may disappear by itself. - D-side
  • @ D-side with num seemed to help me above, but with the base I don’t know how to solve the problem. - Vladislav
  • @Vladislav add somewhere, in what form the code is now and what errors the compiler displays (and, please, with text, not screenshots). - D-side
  • Here is the link to the code - yadi.sk/d/2_edazr03JXSBb . - Vladislav

The word new is a keyword in C ++. Choose another name for this variable.

  • I changed this SI, it still displays errors - Vladislav
  • Perhaps somewhere a typo. - Vanyamba Electronics
  • Even if this si and new is not there, you still need to pay attention to the choice of names. If you ask the store - wrap me up with a new one, then hardly anyone will understand what you want. - 0xdb