PDCURSES assignign value to integer make error

91 views Asked by At

I'm using PDCURSES on Windows 7 and my program stops working at the beginning. I noticed the error is made by assigning value to integer in line: 41 . Unfortunately I have no idea why. I'm writing in C in Code blocks. I would be grateful if someone could help me. Error message

        #include <curses.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define ILOSC_NAZW 5
#define false 0
#define true 1

WINDOW * createwin(int height,int width,int starty,int startx);
void uaktualnij(WINDOW*left,char *nazwa);
void wyswietl_nazwy(WINDOW *right,char **losowe_nazwy);

int poprawnie=0,blednie=0;
int main()
{
    char *losowe_nazwy[ILOSC_NAZW]={"JACK","TOM","KEN","JESSY","ANDRIEJ"};
char str[20];
int c,startx,starty,height,width;

WINDOW *right,*left,*console;
initscr();

refresh();

startx=0,starty=0,height=LINES/2,width=COLS/2;
left=createwin(height,width,starty,startx);
startx=COLS/2;
right=createwin(height,width,starty,startx);
startx=0;
starty=LINES/2;
width=COLS;
console=createwin(height,width,starty,startx);
getmaxyx(right,starty,startx);
uaktualnij(right,NULL);
mvwprintw(left,starty/2-starty/4,startx/2-strlen("PODAJ NAZWE UZYTKOWNIKA")/2,"PODAJ NAZWE UZYTKOWNIKA");
wrefresh(left);
wyswietl_nazwy(left,losowe_nazwy);


c=0;    // assigning value make error


getmaxyx(console,starty,startx);
wmove(console,starty-2,2);
memset(str,0,sizeof *str);
wclear(console);
wborder(console,0,0,0,0,0,0,0,0);
wrefresh(console);

getch();
endwin();
return 0;

}
WINDOW * createwin(int height,int width,int starty,int startx){
WINDOW *mywin=newwin(height,width,starty,startx);
box(mywin,0,0);
wrefresh(mywin);
return mywin;
}
void czekaj(double sec){
clock_t koniec=clock()+sec*CLOCKS_PER_SEC;
while(clock()<koniec)continue;
}
void wyswietl_nazwy(WINDOW *right,char **losowe_nazwy){
int i=ILOSC_NAZW;
int rstartx,rstarty;
getmaxyx(right,rstarty,rstartx);
while( i>=0)
    {

    mvwprintw(right,rstarty/2-rstarty/4+2,rstartx/2-strlen(losowe_nazwy[i])/2,"%s",losowe_nazwy[i]);
    wrefresh(right);
    czekaj(0.2);
    wmove(right,rstarty/2-rstarty/4+2,rstartx/2-strlen(losowe_nazwy[i]));
    wclrtoeol(right);
    mvwaddch(right,rstarty/2-rstarty/4+2,rstartx-1,ACS_VLINE);
    wrefresh(right);
    i--;
}
}

void uaktualnij(WINDOW*left,char *nazwa){
    int startx,starty;
wclear(left);
wborder(left,0,0,0,0,0,0,0,0);
getyx(left,starty,startx);
mvwprintw(left,starty+1,startx+1,"Poprawnie: %i",poprawnie);
mvwprintw(left,starty+2,startx+1,"Blednie: %i",blednie);
if(nazwa!=NULL)
mvwprintw(left,starty+3,startx+1,"Wproawadzona nazwa uzytkowanika: %s",nazwa);
wrefresh(left);
}
1

There are 1 answers

2
EvilTeach On

Since PDCurses is written in C, I am assuming that you are compiling in C.

Move the

int c; 

to just below the line

char *losowe_nazwy[ILOSC_NAZW]={"JACK","TOM","KEN","JESSY","ANDRIEJ"};
int c; 

The C language expects those sorts of definitions to be at the top of the function.