problem v C - retezec vs ukazatel

Jakub Ladman ladmanj
Středa Březen 17 12:04:58 CET 2004


Ja jsem ten, kdo se puvodne ptal.
Uz mi to funguje, nehlede na cistotu programatorskeho stylu.

Pokud nekdo mate minutku muzete se na to mrknout a "oznamkovat" mi to.
Prilezitostne bych uvital radu, ktera by mi naznacila, jakym zpusobem
dosahnout stejneho vysledku aniz by retezce v polich mely konst delku.
Precejen je to program do jednocipu a tak je uspora pameti na miste.

Definice poli je hned na zacatku a potom hledejte funkce forcemnu a prmnu a
jejich volani.
Fce forcemnu je volana trikrat, ve zdrojaku ihned za sebou. prmnu je volana
z forcemnu.

Mimochodem, jsem asi diky tomuhle problemu pochopil zpusob prace s
ukazateli.

Jakub Ladman

//dalsi test
#include <c:\keil\c51\inc\atmel\at89x52.h>
#include <stdio.h>
#include <disp16x2x4.h>   //znakovy vystup presmerovan na LCD display
#include <i2c.h>                //knihovna pro praci s I2C zarizenimi
#include <lm76.h>             //knihovna pro praci s teplomerem LM76 -
pouziva I2C.h
#include <ds1307.h>         //knihovna pro praci s kalendarem DS1307 -
pouziva I2C.h
#include <keyb.h>             //maticova klavesnice 4x4 plus 4x4 led - bezi
pod prerusenim

static char code menu1[3][17]= {"1. INFO         ",
        "2. Teplota      ",
        "3. Cas/Datum    "};
static char code menu2[5][17]= {"1. Zobrazit     ",
        "2. Nizka teplota",
        "3. Vys.  teplota",
        "4. Krit. teplota",
        "5. Hystereze    "};
static char code menu3[3][17]= {"1. Zobrazit     ",
        "2. Upravit cas  ",
         "3. Upravit datum"};

void initherm();
bit prmnu(char item,items, char *menu,bit mode);
unsigned char forcemnu(unsigned char items,char *menu);
void wait(unsigned int miliseconds);
unsigned char modify(unsigned char number,min,max);
//---------
void main ()
{
 unsigned char next;
 initdisp();
 timinit();  //nastavi registry a spusti prerusovani od citace 0 (1kHz)
 initherm();
 onoff(1,0,0);
 clrdsp();
 curhome();
 while(1)
 {
  switch(forcemnu(2,menu1))
  {
   case 0:next=0;break;
   case 1:next=1+forcemnu(4,menu2);break;
   case 2:next=6+forcemnu(2,menu3);break;
  }
  delay(1500);
  switch(next)
  {
   case 0:break;
   case 1:{curhome();printf("Teplota");while(klav==0){gotoxy(1,1);
           printf("t = %4.2f",tempnow());wait(1000);}}break;
   case 2:break;
   case 3:break;
   case 4:break;
   case 5:break;
   case 6:{curhome();printf("Datum/Cas");while(klav==0){gotoxy(1,0);
           printf("%d.%d. %d:%d:%d    ",(unsigned int)rdate(),
           (unsigned int)rmonth(),(unsigned int)rhours(),(unsigned
int)rminutes(),
           (unsigned int)rseconds());wait(1000);}}break;
   case
7:{wseconds(0x80);curhome();printf("Hodina?");whours(modify(rhours(),0,23));
           curhome();printf("Minuta?");wminutes(modify(rminutes(),0,59));
           wseconds(0);}break;
   case 8:{curhome();printf("Rok?");wyear(modify(ryear(),0,99));curhome();

printf("Mesic?");wmonth(modify(rmonth(),1,12));curhome();printf("Den?");
           wdate(modify(rdate(),1,31));}break;
  }
 }
}
//--------
unsigned char forcemnu(char items,char *menu)
{
 bit show=0;
 char mnu=0;
 show = prmnu(mnu,items,menu,show);
 while (1)
 {
  if (klav!=0)
  {
   do {} while(klav!=0);
   switch(pklav)
   {
    case 'O': {mnu--;if (mnu<0) mnu=items;};break;
    case 'N': {mnu++;if (mnu>items) mnu=0;};break;
    case 'M': {clrdsp();return(mnu);pklav=0;}break;
   }
   show = prmnu(mnu,items,menu,show);
  }
 }
}
bit prmnu(char item,items, char *menu,bit mode)
{
 if (mode) {item--;if(item<0) item=items;}
 curhome();printf("%s",&(menu+item*17));
 item++; if(item>items) item=0;
 gotoxy(1,0);printf("%s",&(menu+item*17));
 gotoxy((unsigned char)mode,2);putchar('<');
 return(~mode);
}

void initherm()
{
 wthyreg(bintemp(1));
 wtlowreg(bintemp(23.5));
 wthireg(bintemp(27.31));
 wtcrireg(bintemp(30.18));
}

void wait(unsigned int miliseconds)
{
 unsigned int exittime;
 exittime=rtime+miliseconds;
 while(rtime<exittime){}
}

unsigned char modify(unsigned char number,min,max)
{
 gotoxy(1,0);printf(" %d ",(unsigned int)number);
 while (1)
 {
  if (klav!=0)
  {
   do {} while(klav!=0);
   switch(pklav)
   {
    case 'O': {number--;if (number<min) number=max;};break;
    case 'N': {number++;if (number>max) number=min;};break;
    case 'M': {clrdsp();return(number);pklav=0;}break;
   }
  wait(100);
  gotoxy(1,0);printf(" %d  ",(unsigned int)number);
  }
 }







Další informace o konferenci Hw-list