• B правой части каждого сообщения есть стрелки и . Не стесняйтесь оценивать ответы. Чтобы автору вопроса закрыть свой тикет, надо выбрать лучший ответ. Просто нажмите значок в правой части сообщения.

  • Курсы Академии Кодебай, стартующие в мае - июне, от команды The Codeby

    1. Цифровая криминалистика и реагирование на инциденты
    2. ОС Linux (DFIR) Старт: 16 мая
    3. Анализ фишинговых атак Старт: 16 мая Устройства для тестирования на проникновение Старт: 16 мая

    Скидки до 10%

    Полный список ближайших курсов ...

Допущена ошибка в коде на С, не знаю в чем она заключается

  • Автор темы sSilen
  • Дата начала
S

sSilen

Я написал курсовую,но не понимаю почему выдает ошибку Declaration syntax error, компилятор Borland C\C++ 6
Програма должна моделировать жизнь клетки, условия меньше двух или больше трех соседей умирает клетка, при трёх соседях появляется новая клетка.
из за того что программа получилась бюольшой,опубликую в нескольких сообщениях.


program_mew.c

C++:
//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include "start_life.h"
#include "interface.h"
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>






int main(void)
{
extern struct life area[ver][gor];
int all_mew=0;
int max_mew=0;
struct life *cor=area;
printf("Hello,How you want create the field of cells\n");
printf("If you want create randome press 1\n");
printf("if you want connect file press 2\n");
printf("if you want exit press ESC\n");
switch(getch())
{
case '1':
{
printf("Please Enter maximum number of cells\n");
scanf("%d max_mew=",&max_mew);
all_mew=start_life(max_mew);
break;
}
case '2':
{
int error;
error=loadmass(cor);
if(error==1)
prinf("Error 404: File no Found");
break;
}
case 27:
{

return 0;
break;
}
}
clrscr();
interface(all_mew);
return 0;
}

//---------------------------------------------------------------------------

Добавлено: start_life.h
C++:
#ifndef start_mew_h
#define start_mew_h
#define ver 10
#define gor 10

struct life
{
int y;
int x;
int mew;
int neighbors;
}; 

int start_life(int max_mew);




#endif
start_life.c
C++:
#include <conio.h>
#include <stdlib.h>
#include "start_life.h"
#include "action_mew.h"

struct life area[ver][gor];// выдаёт вот здесь ошибку...Declaration syntax error

int start_life(int max_mew)
{
struct life *cor=area;
int i,j,now;
now=0;
randomize();
for(i=0;i<ver;i++)
{
for(j=0;j<gor;j++)
{
area[j][i].x=j;
area[j][i].y=i;
cor=change_coordinate(i,j,cor);
if(now < max_mew)
{
area[j][i].mew=random(2);
if(area[j][i].mew == 1)
{
now++;

}
}
}

}
return now;
}
print.h
C++:
#ifndef print_h
#define print_h

void print(int time);





#endif
print.c
C++:
#include <stdio.h>
#include <conio.h>
#include "start_life.h"
void print(int time)
{
extern struct life area[ver][gor];
int i,j,t;
for(i=0;i<ver;i++)
{
for(j=0;j<gor;j++)
{
if(area[i][j].mew==0)
printf(".");
else
printf("0");
}
printf("\n");
}
for(t=0;t<time;t++);
clrscr();

}
Добавлено: action_mew.h
C++:
#ifndef action_mew_h
#define action_mew_h


struct coordinate *change_coordinate(int x,int y,struct coordinate *coordinate_array);
void death_or_create()





#endif
action_mew.c
C++:
#include "action_mew.h"
#include "start_life.h"
#include <conio.h>
#include <stdlib.h>


extern struct life area[ver][gor];
void death_or_create()
{
int i,j;
struct life *cor=area;
for(i=0;i<ver;i++)
{
for(j=0;j<gor;j++)
{
if(cor->mew==1)
{
if(cor->neighbors!=2 && cor->neighbors!=3)
{
cor->mew=0;
}
}
else if(cor->mew==0)
{
if(cor->neighbors==3)
{
cor->mew=1;
}
}
cor=change_coordinate(i,j,cor);
cor=area[j][i];
}
}
}

struct life* change_coordinate(int x, int y,struct life *cor)
{
int i,j;
int max_change_x,min_change_x,max_chang e_y,min_change_y;

switch(x)
{
case(0):
{
min_change_x=0;
max_change_x=1;
break;
}
case(gor-1):
{
min_change_x=-1;
max_change_x=0;
break;
}
default:
{
min_change_x=-1;
max_change_x=1;
break;
}

}
switch(y)
{
case(0):
{
min_change_y=0;
max_change_y=1;
break; 
}
case(ver-1):
{
min_change_y=-1;
max_change_y=0;
break;
}
default:
{
min_change_y=-1;
max_change_y=1;
break;
}

}
for(j=min_change_y;j<=max_change_y; j++)
{
for(i=min_change_x;i<=max_change_x; j++)
{
if((i!=0) && (j!=0))
{
if(area[x+i][y+j].mew==0)
{
cor->neighbors++;
}
}
}
}

}
return cor;
}
interface.h
C++:
#ifndef interface_h
#define interface_h

int loadmass(struct life *pt);
void interface(int all_mew);





#endif
Добавлено: interface.c

C++:
#include "interface.h"
#include "action_mew.h"
#include "print.h"
#include "start_life.h"
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>

extern struct life area[ver][gor];

void interface(int all_mew)
{
int step;
int time;
int max_mew;
time=1;
while(1)
{
printf("Hello, If you want to run a simulation of living mews, then select the style of launch:\n");
printf("Press 1 if an automatic mode.\n");
printf("Press 2 if you want to run in step-by-step.\n");
printf("Press 3 if you want to change the display time (in seconds).\n");
printf("Press 4 if you want to change the fild size.\n" );
printf("Press 5 if you want to change the max amount mew.\n");
printf("Press 6 if you want to see statistec.\n");
printf("Press ESC to exit.\n");
switch(getch())
{
case'1':
{
time=10000*time;
print(time);
while(1)
{
death_or_create();
print(time);
}
break;
}
case '2':
{
int j;
int exit=0;
time=10000*time;
printf("please,enter amount step\n");
scanf("%d\n",&step);
print(time);
while(exit!=1)
{
printf("Press 1 for next step\t Press 2 for see a statictic\t Press ESC for Exit");
switch(getch())
{
case '1':
{
death_or_create();
for(j=0;j<(step+1);j=j+step)
{
print(time);
}
}

case '2':
{
int i,j;
int now_amount=0;
for(i=0;i<ver;i++)
{
for(j=0;j<gor;j++)
{
if(area[j][i].mew==1)
{
now_amount++;
printf('now_amount',"%d-mew:");
printf("\nx=%d",'j',"\ny=%d",'i');
printf("neighbors:%d\n",'area[j][i].neighbors');
}
}
}

}
case 21:
{
exit=1;
break;
}
}
}
break;
}
case '3':
{
printf("please,enter time");
scanf("%d time=",&time);
break;
}
case '4':
{ printf("Sorry,but this peace of program don't work");
break;
}
case '5':
{
printf("please,enter max start mew");
scanf("%d max_start_mew=",&max_mew);
break;
}
case '6':
{
int i,j;
int now_amount=0;
for(i=0;i<ver;i++)
{
for(j=0;j<gor;j++)
{
if(area[j][i].mew==1)
{
now_amount++;
printf('now_amount',"%d-mew:");
printf("\nx=%d",'j',"\ny=%d",'i');
printf("neighbors:%d\n",'area[j][i].neighbors');
}
}
}

}
case 27:
{

return 0;
break;
}


}
}
}
int loadmass(struct life *pt)
{
char i=';';
FILE *pf;
if((pf=fopen("New_field.txt","r"))! =NULL)
{
rewind(pf);
while(!feof(pf))
{
fscanf(pf,"%d,%d", &pt->x,&pt->y);
fscanf(pf,"%c",&i);
pt++;
}
return 0;
}
else
{
fclose(pf);
return 1;
}
}
P.S. если найдете где нить логические или синтаксические ошибки пишите,буду премного благодарен)
и так же как можно осуществить изменения размера массива?)
P.S.S. заранее спасибо^^
 
R

RiCrO

:(

Используй (code=cpp)Твой листинг(/code) и ( () замени на [] ) и не позорься. Твою "ахинею" никто читать не будет...


Если не дошло, то отредактируй свой пост и найди кнопочку [C++]

Должно быть как-то так хотя бы, не говоря уже о культуре написания листинга.

C++:
pragma argsused
#include "start_life.h"
#include "interface.h"
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>






int main(void)
{
extern struct life area[ver][gor];
int all_mew=0;
int max_mew=0;
struct life *cor=area;
printf("Hello,How you want create the field of cells\n");
printf("If you want create randome press 1\n");
printf("if you want connect file press 2\n");
printf("if you want exit press ESC\n");
switch(getch())
{
case '1':
{
printf("Please Enter maximum number of cells\n");
scanf("%d max_mew=",&max_mew);
all_mew=start_life(max_mew);
break;
}
case '2':
{
int error;
error=loadmass(cor);
if(error==1)
prinf("Error 404: File no Found");
break;
}
case 27:
{

return 0;
break;
}
}
clrscr();
interface(all_mew);
return 0;
}
 
R

RiCrO

s Silen, вопрос по-существу: На каком этапе происходит ошибка? Этап компиляции или уже при выполнении программы?
 
S

sSilen

:(

Используй (code=cpp)Твой листинг(/code) и ( () замени на [] ) и не позорься. Твою "ахинею" никто читать не будет...


Если не дошло, то отредактируй свой пост и найди кнопочку [C++]

Должно быть как-то так хотя бы, не говоря уже о культуре написания листинга.


теперь похоже на правду? Я просто первый раз обращаюсь так за помощью...

Ошибка проходит на этапе компиляции..
 
R

Rififi

sSilen

не понимаю почему выдает ошибку Declaration syntax error

В C/C++ предварительная декларация функций должна завершаться оператором "точка с запятой"
 
S

sSilen

...
#include "action_mew.h"

struct life area[ver][gor];// выдаёт вот здесь ошибку...Declaration syntax error

int start_life(int max_mew)
...
помойму все врено,точка с запятой есть... но ошибку выдает именно в этом месте)
 
R

RiCrO

s Silen, читай что пишет компилятор. У тебя ошибка в синтоксисе декларации.

Не знаю, но возможно у тебя не хватает extern. Попробуй вставить.
 
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!