Witam!
Czego mi brakuje jeśli wyświetla mi taki błąd jak w temacie, z gotoxy i clrscr już sobie poradziłem dołączając conio2.h i linkera -lconio a rozwiązania problemu z window nie mogłem nigdzie znaleźć,proszę o pomoc z góry dziękuje.
Witam!
Czego mi brakuje jeśli wyświetla mi taki błąd jak w temacie, z gotoxy i clrscr już sobie poradziłem dołączając conio2.h i linkera -lconio a rozwiązania problemu z window nie mogłem nigdzie znaleźć,proszę o pomoc z góry dziękuje.
bo w mingwowym conio nie ma funkcji o nazwie window
.
To czym można to odpalić albo zastąpić jakąś inną funkcją? Ogólnie korzystam z wxDev-C++ 7.3.1.3
a do czego ona służy? pokaż kod.
funkcja window ogranicza pole tekstowe do współrzędnych jakie się poda
window(left,top,bottom,right)
Jak się usunie tą funkcje to gdy stworzy się nowy plik nie ma możliwości przeglądania rekordów i w ogóle nie wyświetla legendy, a rekordy są drukowane w lewym górnym rogu okna.
//
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <math.h>
#include <conio2.h>
//-----------------------------------------
#define NAZWA_MAX 50
struct fotorezystor
{
int id;
char nazwa[NAZWA_MAX];
double par1, par2, par3, par4, par5;
};
void dopisz(int *nr); // F5
void usun(char *s,int *p_file_size); // F6
void modyfikuj(void); // F7
void sortuj (int *); // F8
void drukuj_rekord();
void drukuj_p();
int menu (void);
int edycja(void);
void status(char *s);
FILE *fp;
char s[30]="plik.dat";
char errMessage[100] = "";
int getString(char* ref, int max)
{
char tmp[NAZWA_MAX + 1];
scanf("%s", tmp);
if(strlen(tmp) > max)
{
strcpy(errMessage, "Wpisany ciag jest za długi.");
return 1;
}
strcpy(ref, tmp);
return 0;
}
int getDouble(double* ref)
{
int res = scanf("%lf", ref);
if(*ref == 1.0/0.0 || res == 0)
{
strcpy(errMessage, " Dana nie jest poprawna liczba typu double.");
return 1;
}
return 0;
}
int main(int argc, char **argv)
{
char ch;
/*struct fotorezystor tab[4]={
{ 1, "Pierwszy", 10, 20, 30, 40, 50 },
{ 2, "Drugi", 10, 20, 30, 40, 50 },
{ 3, "Trzeci", 10, 20, 30, 40, 50 },
{ 4, "Czwarty", 10, 20, 30, 40, 50 },
};
fp=fopen(s,"w+b");
fwrite(&tab,sizeof(struct fotorezystor),4,fp);
fclose(fp);
*/
while (menu() != 1) ;
return 0;
}
int menu (void)
{
char ch,size;
window(1,1,80,25);
clrscr();
gotoxy(10,10);
cprintf(" 1. Nowy plik");
gotoxy(10,11);
cprintf(" 2. Otworz plik");
gotoxy(10,12);
cprintf(" 3. Zakoncz ");
fflush(stdin);
do
{
ch=getch();
}
while (ch!='1' && ch!='2' && ch!='3'&& ch!=27);
switch (ch)
{
case '1':
utworz();
break;
case '2':
otworz();
break;
case 27 :case '3':
return 1;
}
return 0;
}
int otworz (void)
{
do
{
clrscr();
gotoxy(1,15);
printf("Nazwa pliku: ");
scanf("%s", s);
fp=fopen(s,"r+");
} while(fp == NULL);
edycja();
fclose(fp);
fseek(fp,0L,SEEK_END);
}
int utworz (void)
{
do
{
clrscr();
gotoxy(1,15);
printf("Nazwa pliku: ");
scanf("%s", s);
fp=fopen(s,"w+");
} while(fp == NULL);
edycja();
fclose(fp);
fseek(fp,0L,SEEK_END);
}
int edycja (void)
{
int i,size,file_size;
int ch1,ch2,nr;
struct fotorezystor st;
size=sizeof(struct fotorezystor);
fseek(fp,0L,SEEK_END);
file_size=ftell(fp)/size;
fseek(fp,0L,SEEK_SET);
fread(&st,sizeof(struct fotorezystor),1,fp);
clrscr();
gotoxy(1,1);
printf(" Przeglad F5-Dopisz F6-Usun F7- Modyfikuj F8- Sort Esc-Menu");
gotoxy(1,25);
status("PRZEGLAD PgDn PgUp \030 \031 Home End ");
window(1,10, 40,24);
if ( file_size!= 0 ) drukuj_p();
do
{
ch1=getch();
ch2=0;
if (ch1==0) ch2=getch();
if (ch1==27) ch2=27;
if (ch1>=49&&ch1<=60) ch2=ch1;
switch(ch2)
{
case 72:case 73:case 56: case 57: //PgUp lub strzalka w gore
if ((ftell(fp)-size)>0)
fseek(fp,-2L*size,SEEK_CUR);
else
fseek(fp,0L,SEEK_SET);
if ( file_size!= 0 ) drukuj_rekord();
break;
case 80:case 81:case 50:case 51: //PgDn lub strzalka w dol
if ( ftell(fp)/size<file_size)
if ( file_size!= 0 ) drukuj_rekord();
break;
case 71:case 55: // Home - poczatek
fseek(fp,0L,SEEK_SET);
if ( file_size!= 0 ) drukuj_rekord();
break;
case 79:case 49: // End - koniec
fseek(fp,-1L*size,SEEK_END);
if ( file_size!= 0 ) drukuj_rekord();
break;
case 27: return 0;
break;
case 63 : dopisz(&file_size); // F5
drukuj_p();
break;
case 64 : usun(s,&file_size);
drukuj_p(); // F6
break;
case 65 : if ( file_size == 0 ) break;
modyfikuj(); // F7
drukuj_p();
break;
case 66 : sortuj (&file_size);
drukuj_p();
}
}
while (1);
}
struct fotorezystor pobierz()
{
struct fotorezystor st;
while(1)
{
fflush(stdin);
printf("\n Nazwa : ");
if(getString(st.nazwa, NAZWA_MAX) == 0) break;
printf("Blad\n");
getch();
gotoxy(1,4);
}
while(1)
{
fflush(stdin);
printf(" Parametr1 : ");
if(getDouble(&st.par1) == 0) break;
printf(" Blad.\n");
gotoxy(1,5);
printf(" \r");
}
while(1)
{
fflush(stdin);
printf(" Parametr2 : ");
if(getDouble(&st.par2) == 0) break;
printf(" Blad.\n");
gotoxy(1,6);
printf(" \r");
}
while(1)
{
fflush(stdin);
printf(" Parametr3 : ");
if(getDouble(&st.par3) == 0) break;
printf(" Blad.\n");
gotoxy(1,7);
printf(" \r");
}
while(1)
{
fflush(stdin);
printf(" Parametr4 : ");
if(getDouble(&st.par4) == 0) break;
printf(" Blad.\n");
gotoxy(1,8);
printf(" \r");
}
while(1)
{
fflush(stdin);
printf(" Parametr5 : ");
if(getDouble(&st.par5) == 0) break;
printf(" Blad.\n");
gotoxy(1,9);
printf(" \r");
}
return st;
}
void dopisz(int *p_nr) // F5
{
char ch;
int nr_rek;
int i=0;
struct fotorezystor st;
status("DOPISZ");
fseek(fp,0L,SEEK_END);
nr_rek=ftell(fp)/sizeof(struct fotorezystor);
while(1)
{
clrscr();
fflush(stdin);
printf("\n");
printf("\n Rekord nr %d ",++nr_rek);
st = pobierz();
st.id = nr_rek;
fwrite(&st,sizeof( struct fotorezystor),1,fp);
*p_nr=nr_rek;
printf("\n Nastepny rekord t/n?");
fflush(stdin);
ch=toupper(getc(stdin));
if (ch=='N')
break;
}
clrscr();
status("PRZEGLAD");
fflush(stdin);
}
void usun(char *s,int *p_file_size) // F6
{
int handle;
int nr_rek,ilosc;
struct fotorezystor st;
status("USUN ");
clrscr();
nr_rek=ftell(fp)/sizeof(struct fotorezystor);
fseek(fp,-1L*sizeof(struct fotorezystor),SEEK_END);
fread(&st,sizeof(struct fotorezystor),1,fp);
fseek(fp,(nr_rek-1)*sizeof(struct fotorezystor),SEEK_SET);
fwrite(&st,sizeof(struct fotorezystor),1,fp);
fseek(fp,0L,SEEK_END);
ilosc=ftell(fp)/sizeof(struct fotorezystor);
fclose(fp);
if ((handle=open(s,O_RDWR|O_BINARY))==-1)
printf("\n plik nie został otwarty");
chsize(handle,(ilosc-1)*sizeof(struct fotorezystor));
close(handle);
fp=fopen(s,"r+b");
fseek(fp,0L,SEEK_END);
*p_file_size=ftell(fp)/sizeof(struct fotorezystor);
fseek(fp,0L,SEEK_SET);
status("PRZEGLAD");
fflush(stdin);
}
void modyfikuj(void) // F7
{
int nr_rek;
struct fotorezystor st;
clrscr();
printf("\ Modyfikuj ");
nr_rek=ftell(fp)/sizeof(struct fotorezystor); // numer modyfikowanego rekordu
printf("\n Nr rekordu: %d\n", nr_rek);
st = pobierz();
st.id = nr_rek;
fseek(fp,-1L*sizeof(struct fotorezystor),SEEK_CUR);
fwrite(&st,sizeof(struct fotorezystor),1,fp);
fflush(stdin);
clrscr();
}
void sortuj (int *p_nr) // F8
{
int i,zam;
struct fotorezystor st1,st2;
status("SORTUJ");
do
{
zam=0;
fseek(fp,0L,SEEK_SET);
for (i=0;i<*p_nr-1;i++)
{
fseek(fp,i*sizeof (struct fotorezystor),SEEK_SET);
fread(&st1,sizeof(struct fotorezystor),1,fp);
fread(&st2,sizeof(struct fotorezystor),1,fp);
if (strncmp (st1.nazwa, st2.nazwa, NAZWA_MAX)>0)
{
fseek(fp,i*sizeof(struct fotorezystor),SEEK_SET);
fwrite(&st2,sizeof(struct fotorezystor),1,fp);
fwrite(&st1,sizeof(struct fotorezystor),1,fp);
zam=1;
}
}
}
while (zam);
clrscr();
fseek(fp,0L,SEEK_SET);
status("PRZEGLAD");
//getch();
fflush(stdin);
}
void drukuj_rekord()
{
int nr_rek,size;
struct fotorezystor st;
size=sizeof(struct fotorezystor);
fread(&st,sizeof(struct fotorezystor),1,fp);
nr_rek=ftell(fp)/size;
clrscr();
printf("id: %d \nNazwa: %s\nParametr1: %lf\nParametr2: %lf\nParametr3: %lf\nParametr4: %lf\nParametr5: %lf ",st.id, st.nazwa, st.par1, st.par2, st.par3, st.par4, st.par5);
}
void drukuj_p(void)
{
struct fotorezystor st;
clrscr();
fseek(fp,0L,SEEK_SET);
fread(&st,sizeof(struct fotorezystor),1,fp);
printf("id: %d \nNazwa: %s\nParametr1: %lf\nParametr2: %lf\nParametr3: %lf\nParametr4: %lf\nParametr5: %lf ",st.id, st.nazwa, st.par1, st.par2, st.par3, st.par4, st.par5);
}
void status(char *s)
{
window(1,1, 40,25);
gotoxy(1,25);
printf("Status:%s",s);
window(1,10, 40,24);
}
Użyj biblioteki ncurses. Tam będą okna. Ale trzeba będzie przerobić program.