• Welcome to TUKE FÓRUM - Fórum pre študentov Technickej Univerzity v Košiciach.
 

ZADANIA Z predmetu PROGRAMOVANIE

Started by psicho, 29.01.2010, 17:40:30

« predchdzajce - alie »

profesionale

Mam problem pri kompilovani na omege.

Ked dam skompilovat tak mi vypise zopar warningov.

Napr:

./main.c:27: warning: implicit declaration of function âfacingEastâ

a tomto riadku mam
if(facingEast())
{
int turnBack();
}
else if(facingSouth())
{
int turnRight();
}
else if(facingNorth())
{
int turnLeft();
}
if(!frontIsClear())
{
turnLeft();
while(frontIsClear())
movek();
turnLeft();
}
else
{
while(frontIsClear())
movek();
turnLeft();
movek();
while(frontIsClear())
movek();
turnLeft();
movek();

}
}


definovanie funkcie je tu
int facingSouth()
{
  if (karel_direction == 270) return 1;
    else return 0;
}


Neviete nahodu co ta chyba znamena lebo nikde to neviem najst. Dakujem

psicho

read my blog> www.codemazing.com <read my blog

profesionale

tak teraz mi zase vypisalo toto

In file included from ./main.c:5:
./library.h: At top level:
./library.h:10: error: redefinition of âkarel_beepersâ
./library.h:10: error: previous definition of âkarel_beepersâ was here
./library.h:11: error: redefinition of âkarel_directionâ
./library.h:11: error: previous definition of âkarel_directionâ was here
./library.h:12: error: redefinition of âbeepSâ
./library.h:12: error: previous definition of âbeepSâ was here
./library.h:19: error: nested redefinition of âenum Directionâ
./library.h:19: error: redeclaration of âenum Directionâ
./library.h:20: error: redeclaration of enumerator âEASTâ
./library.h:20: error: previous definition of âEASTâ was here
./library.h:21: error: redeclaration of enumerator âWESTâ
./library.h:21: error: previous definition of âWESTâ was here
./library.h:22: error: redeclaration of enumerator âNORTHâ
./library.h:22: error: previous definition of âNORTHâ was here
./library.h:24: error: redeclaration of enumerator âSOUTHâ
./library.h:24: error: previous definition of âSOUTHâ was here
./library.h:26: error: nested redefinition of âenum Booleanâ
./library.h:26: error: redeclaration of âenum Booleanâ
./library.h:27: error: redeclaration of enumerator âFalseâ
./library.h:27: error: previous definition of âFalseâ was here
./library.h:29: error: redeclaration of enumerator âTrueâ
./library.h:29: error: previous definition of âTrueâ was here
./library.h:32: error: redefinition of âstruct Robotâ
./library.h:40: error: redefinition of âstruct Worldâ

a moj library.h vyzera takto
#include <stdio.h>
#include <stdlib.h>

#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0


int karel_beepers = 20;
int karel_direction = 0;
int beepS = 1;

char * smer();


// aktualna poloha robota
//enum Direction
enum Direction {
     EAST = 0,
     WEST = 180,
     NORTH = 90,
     SOUTH = 270
};

enum Boolean {
     False = 0,
     True = 1
};

//struktura Robot
struct Robot {
       int x;
       int y;
       int beepers;
       
};
struct Robot karel;

struct World {
  int width, height;
  int data[MAX_HEIGHT][MAX_WIDTH];
};


psicho

read my blog> www.codemazing.com <read my blog

swam

pocujte ludia...mam taky mensi problem z tou vymrdanou omegou...skompilujem svoj program,secko v poho spravi..a dam spustit karlika a mi to nerobi pekne po kroku ale vykresluje kazdy jeden jeho pohyb jakeby screenshot...takze mam za sebou obrazky kazdeho jedneho kroku co spravi...heh,pricom vo funkcii draw() mam ten system("clear") na premazanie obrazovky...neviete niekto kde este moze byt chyba???

profesionale

prosim ta a co tam mam zle....mohol by si mi s tym pomost. Prosim ta.

psicho

ta vsak rob podla cviceni ni ?  tam to mas presne

no v podstate musis dat do .h deklaracie vsetkych funkcii ktore xes vydiet mimo .c suboru ...teda v inom zdrojaku

a do .c davas  definiciu potom tych funkcii a ked mas len vramci jeden kompilacnej jednotky funkcie tak ich deklaracia musi byt uvedena vzdy pred ich pouzitim , lebo C compilator je lenivy a nexesamu X krat prechadzat ten isty zdrojak
read my blog> www.codemazing.com <read my blog

profesionale

cize z main je include iba na library.h z library.c volanie na library.h nieje a teraz mi ta posahana omega hadze toto:

./library.c: In function âturnOnâ:
./library.c:15: error: âkarelâ undeclared (first use in this function)
./library.c:15: error: (Each undeclared identifier is reported only once
./library.c:15: error: for each function it appears in.)
./library.c:17: error: âworldâ undeclared (first use in this function)
./library.c: In function âturnOnFileâ:
./library.c:29: warning: implicit declaration of function âreadWorldFileâ
./library.c: In function âsaveFileâ:
./library.c:34: warning: implicit declaration of function âwriteWorldFileâ
./library.c: In function âdrawâ:
./library.c:48: warning: implicit declaration of function âdrawStatusâ
./library.c:51: error: âworldâ undeclared (first use in this function)
./library.c:61: error: âkarelâ undeclared (first use in this function)
./library.c:79: error: âEMPTYâ undeclared (first use in this function)
./library.c:83: error: âWALLâ undeclared (first use in this function)
./library.c:89: error: âbeepSâ undeclared (first use in this function)
./library.c:106: warning: implicit declaration of function âusleepâ
./library.c: At top level:
./library.c:110: warning: conflicting types for âdrawStatusâ
./library.c:48: warning: previous implicit declaration of âdrawStatusâ was here
./library.c: In function âdrawStatusâ:
./library.c:114: error: âkarelâ undeclared (first use in this function)
./library.c:114: warning: implicit declaration of function âsmerâ
./library.c:114: warning: implicit declaration of function â_beepersAtCurrentPositionâ
./library.c:114: warning: format â%sâ expects type âchar *â, but argument 4 has type âintâ
./library.c: In function âturnLeftâ:
./library.c:124: error: âkarelâ undeclared (first use in this function)
./library.c: In function âturnRightâ:
./library.c:130: error: âkarelâ undeclared (first use in this function)
./library.c: In function âturnBackâ:
./library.c:137: error: âkarelâ undeclared (first use in this function)
./library.c: In function âfrontIsClearâ:
./library.c:149: error: âkarelâ undeclared (first use in this function)
./library.c:153: error: âworldâ undeclared (first use in this function)
./library.c:153: error: âWALLâ undeclared (first use in this function)
./library.c: In function âleftIsClearâ:
./library.c:206: error: âkarelâ undeclared (first use in this function)
./library.c:210: error: âworldâ undeclared (first use in this function)
./library.c:210: error: âWALLâ undeclared (first use in this function)
./library.c: In function ârightIsClearâ:
./library.c:262: error: âkarelâ undeclared (first use in this function)
./library.c:266: error: âworldâ undeclared (first use in this function)
./library.c:266: error: âWALLâ undeclared (first use in this function)
./library.c: In function âfacingSouthâ:
./library.c:320: error: âkarelâ undeclared (first use in this function)
./library.c: In function âfacingNorthâ:
./library.c:332: error: âkarelâ undeclared (first use in this function)
./library.c: In function âfacingWestâ:
./library.c:344: error: âkarelâ undeclared (first use in this function)
./library.c: In function âfacingEastâ:
./library.c:356: error: âkarelâ undeclared (first use in this function)
./library.c: In function âbeepersInBagâ:
./library.c:368: error: âkarelâ undeclared (first use in this function)
./library.c: In function âbeepersPresentâ:
./library.c:385: error: âworldâ undeclared (first use in this function)
./library.c:385: error: âkarelâ undeclared (first use in this function)
./library.c: In function âputBeeperâ:
./library.c:391: error: âworldâ undeclared (first use in this function)
./library.c:391: error: âkarelâ undeclared (first use in this function)
./library.c: In function âpickBeeperâ:
./library.c:402: error: âworldâ undeclared (first use in this function)
./library.c:402: error: âkarelâ undeclared (first use in this function)
./library.c: In function â_beepersAtCurrentPositionâ:
./library.c:411: error: âworldâ undeclared (first use in this function)
./library.c:411: error: âkarelâ undeclared (first use in this function)
./library.c: In function âmovekâ:
./library.c:422: error: âkarelâ undeclared (first use in this function)
./library.c: At top level:
./library.c:446: error: conflicting types for âsmerâ
./library.c:114: error: previous implicit declaration of âsmerâ was here
./library.c:489: warning: conflicting types for âreadWorldFileâ
./library.c:29: warning: previous implicit declaration of âreadWorldFileâ was here
./library.c: In function âreadWorldFileâ:
./library.c:501: error: âworldâ undeclared (first use in this function)
./library.c:501: error: âkarelâ undeclared (first use in this function)
./library.c:508: error: âMAX_WIDTHâ undeclared (first use in this function)
./library.c:508: error: âMAX_HEIGHTâ undeclared (first use in this function)
./library.c:525: error: âWALLâ undeclared (first use in this function)
./library.c: At top level:
./library.c:536: warning: conflicting types for âwriteWorldFileâ
./library.c:34: warning: previous implicit declaration of âwriteWorldFileâ was here
./library.c: In function âwriteWorldFileâ:
./library.c:539: error: âworldâ undeclared (first use in this function)
./library.c:539: error: âkarelâ undeclared (first use in this function)
./library.c:543: error: âWALLâ undeclared (first use in this function)
make: *** [library.o] Error 1

library.h
#ifndef LIBRARY_H
#define LIBRARY_H

#include <stdio.h>
#include <stdlib.h>

#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0

#define EAST 0
#define NORTH 90
#define WEST 180
#define SOUTH 270


char * smer();

enum Boolean {
     False = 0,
     True = 1
};

struct Robot {
    int x;
    int y;
    int beepers;
int direction;   
};
struct Robot karel;


struct World {
  int width, height;
  int data[MAX_HEIGHT][MAX_WIDTH];
};

// World 'world' - global variable
struct World world;


void drawStatus();


// Saves world to file output.kw.
// File will be rewritten if exists.
void turnOff();

// Draws world to standard output.
void draw();

// Draws information about world to standard output.
void drawStatus();


// Returns false if in front of robot is wall or is
// out of map.
int frontIsClear();

// Negation of frontIsClear()
int frontIsBlocked();

// Returns false if left to the robot is wall or is
// out of map.
int leftIsClear();

// Negation of leftIsClear()
int leftIsBlocked();

// See leftIsClear().
int rightIsClear();

// Negation of rightIsClear()
int rightIsBlocked();

// Returns true if there are any beepers in the bag.
int beepersInBag();

// Returns true if there are no beepers in the bag.
int noBeepersInBag();


// Returns count of beepers at current position.
int _beepersAtCurrentPosition();

// Returns robot's direction as string.
char * smer();

// Converts (int) direction to character, like N, S, E, W.
char directionToWord(int direction);

// Loads world from file specified by path parameter.
void readWorldFile(char *path);

// Saves current world to file specified by path parameter.
void writeWorldFile(char *path);
#endif

Pokial som to pochopil tak netaha define.vsetko ostatne natiahne. Teraz nechapem. Ako programujem weby a vzdy som si myslel ze najhorise je spravit kompatibilitu pre IE, Firefox, Safari a podobne....ale vidim ze som sa zmylil.....omega prekonala....

fail

QuoteCitácia
tazko povedat, ze co to znamena, ze co to znamena, ze jednoducho vobec nejde na tej omege. ak som dobre rozumel - pouzivas ncurses funkcie? vo windowsoch prikladas do projektu pdcurses? kompilacia pod linuxom ti zbehne? nezabudol si tam pre prekladac nechat poznamku, ze ma pouzit aj ncurses kniznicu (-lcurses)?
.. poviem to takto... mam obycajneho karla (bez curses) ten mi ide vo wine aj na omege(bez system("pause/cls") ).. potom mam karla s curses vo wine ide vsetko v pohode... ked ho ale prerobim do linuxu (takym istym sposobom ako toho "obycajneho" karla).. tak kompilacia prebehne vporiadku ale vysledny program nefunguje --> tj vykresli svet a pod neho jeho polku a dalej nerobi nic... a sposobi to este to ze cele putty sa mi bugne .. cize stale to vypinam zapinam ... spravil som taky "pokus" ... ked som toho "linuxoveho" curses karla spustil vo windowse tak isiel tak ako mal (hoci tam preblikavalo, ze nepozna prikaz clear).. tak uz fakt neviem co to chce

tommy-sv

Quote from: n3r0 on  11.05.2010, 22:53:31
nejaký fajnový debuger na C .. (windows.. devcpp pripadne iný)kde by som mohol vidieť obsah premennej ,hodnoty nadobudnuté na aktuálnych pozíciách v programe ..atd ..{skusal som gdb +dev ak by ste vedeli o niečom ++ ;w}

Zrejme nepoviem novinku ale ked Windows tak zeby Visual Studio? Ja by som pre C/C++ nevymenil za nic ine.  :zuzka:
"Čím skôr zomrieš, tým dlhšie budeš mŕtvy."
"Radšej viac vypiť, ako menej zjesť."

Maroshv

  [Linker error] undefined reference to `usleep'
  [Linker error] undefined reference to `WinMain@16'
  ld returned 1 exit status

stále nejaka chyba, jednu chybu odstranim, a objaví sa dalšia a nakoniec toto :(

prosím pomôžte, najlepšie cez ICQ 262322023, pošlem zdrojak :)
To že si chodil/a na sociálnu prácu a ,že ju maš skončenú neznamená ,že si vysokoškolsky vzdelaný a vážený občan, tak sa mi tu neohaňaj nejak titulom. Socialná práca to nieje vysoká škola.

Robokop

ludia pls, co tu mam zle v tejto funkcii? v maine mozem napisat ako prvy ktorykolvek prikaz okrem movek() a vsetko ide ok ale ked dam movek() tak mi to nechce nacitat vobec subor vypise mi chybu pri otvarani a uz som z toho na nervy...pls help


void turnOn(char *name){                                      
 
  int x,y,z;
 
 
  FILE *f;
  f=fopen(name,"r");
  if(f==NULL)
    {
        printf("Chyba pri otvarani suboru...\n");
    }
 
      fscanf(f,"%d %d %d %d %c %d",&WORLD.width,&WORLD.height,&ROBOT.x,&ROBOT.y,&c,&ROBOT.beepers);
 
   switch(c)
    {
         case 'N':
             ROBOT.direction=NORTH;
             break;
         case 'S':
             ROBOT.direction=SOUTH;
             break;
         case 'E':
             ROBOT.direction=EAST;
             break;
         default:
             ROBOT.direction=WEST;
    }
   
 for(i=0;i<WORLD.height;i++) {
     for (j=0;j<WORLD.width;j++) {
         WORLD.world[j]=EMPTY;
         }}
     
   for(i=0;i<WORLD.height;i++) {
     for (j=0;j<WORLD.width;j++) {
         WORLD.world[j]=EMPTY;
         }}
     
     while(TRUE==fscanf(f,"%c",&c))
    {
         if(c=='W')                                  
         {
              fscanf(f,"%d %d\n",&i,&j);
              WORLD.world[j]=WALL;
         }
         else if(c=='B')                            
         {
              fscanf(f,"%d %d %d\n",&i,&j,&z);
              WORLD.world[j]=z;
         }
    }
}

profesionale

Quote from: Maroshv on  11.05.2010, 23:31:32
  [Linker error] undefined reference to `usleep'
  [Linker error] undefined reference to `WinMain@16'
  ld returned 1 exit status

stále nejaka chyba, jednu chybu odstranim, a objaví sa dalšia a nakoniec toto :(

prosím pomôžte, najlepšie cez ICQ 262322023, pošlem zdrojak :)
No ja sa bojim ze to asi nedas dokopy....lebo usleep je to iste ako sleep ale s tym rozdielom ze uslep je na unix. Pri windows sa do sleep udavaju ms tak pri unixe su to sekundy.

Maroshv

Quote from: profesionale on  12.05.2010, 00:02:12
Quote from: Maroshv on  11.05.2010, 23:31:32
  [Linker error] undefined reference to `usleep'
  [Linker error] undefined reference to `WinMain@16'
  ld returned 1 exit status

stále nejaka chyba, jednu chybu odstranim, a objaví sa dalšia a nakoniec toto :(

prosím pomôžte, najlepšie cez ICQ 262322023, pošlem zdrojak :)
No ja sa bojim ze to asi nedas dokopy....lebo usleep je to iste ako sleep ale s tym rozdielom ze uslep je na unix. Pri windows sa do sleep udavaju ms tak pri unixe su to sekundy.

no ked som to prepísal na sleep, teraz už kompiler nič nevyhadzuje, problem ,je že to beží strašne rychlo a pritom vypisuje nejake error :(
To že si chodil/a na sociálnu prácu a ,že ju maš skončenú neznamená ,že si vysokoškolsky vzdelaný a vážený občan, tak sa mi tu neohaňaj nejak titulom. Socialná práca to nieje vysoká škola.

tommy-sv

Quote from: profesionale on  12.05.2010, 00:02:12
Quote from: Maroshv on  11.05.2010, 23:31:32
  [Linker error] undefined reference to `usleep'
  [Linker error] undefined reference to `WinMain@16'
  ld returned 1 exit status

stále nejaka chyba, jednu chybu odstranim, a objaví sa dalšia a nakoniec toto :(

prosím pomôžte, najlepšie cez ICQ 262322023, pošlem zdrojak :)
No ja sa bojim ze to asi nedas dokopy....lebo usleep je to iste ako sleep ale s tym rozdielom ze uslep je na unix. Pri windows sa do sleep udavaju ms tak pri unixe su to sekundy.

usleep() pracuje s mikrosekundami ak ma pamat neklame (neklame: http://www.opengroup.org/onlinepubs/007908799/xsh/usleep.html), a este napr. Microsoft C run time nema sleep(int neviemakecesonds) ale Sleep(int miliseconds)
"Čím skôr zomrieš, tým dlhšie budeš mŕtvy."
"Radšej viac vypiť, ako menej zjesť."

Palike

ako spravim tuto funkciu?..

void setStepDelay(int) - Sets delay of one Karel's step in miliseconds.

skusal som nieco take..

void setStepDelay(int e)
{
sleep(e);
}

ale nejak to neslo :D

fail

ok.. ked uz ma vsetci ignoruju  ;D mozno cez video vam to bude pohodlnejsie http://www.screentoaster.com/watch/stUEtdQkVLRFtYQ1hVXVJRV1dc

ursus

omg ved, vsade kde mas sleepy v tych funkciach kde ho treba, das miesto coajvem sleep(500), sleep(e) a toto e budes fciou setstepdelay menit
So this router walks into the doctor's office...
- Doctor, it hurts when IP.

mirek

Quote from: fail on  12.05.2010, 00:56:56
ok.. ked uz ma vsetci ignoruju  ;D mozno cez video vam to bude pohodlnejsie

vazne uz mam lepsiu predstavu o tom, co si sa snazil opisat ;) akym sposobom mazes obrazovku? lebo pri pohlade na to blikanie by som povedal, ze volas dakde system("cls/clear"). alebo pouzivas ncursovsku funkciu?
So say we all!

Joey_XD

#694
Kto mi vysvetli jednu vec.... Na ubuntu mi ide Karol perfektne, riesi problem ako ma... Ale ked skopirujem tie iste zdrojaky na omegu, prelozim cez make (preklad prebehne bez chyb), lenze pri spusteni programu Karol v jednom okamihu zastane a vypise ze narazil do steny, aj ked uz cez to niesto presiel predtym.... Uz fakt neviem co s tym je... v algorytme by nemala byt chyba ked na ubuntu to ide bez chybycky.


a to som este zabudol, ze pri tom kroku co zastane je podmienka if(frontIsClear){movek()} ... cize nechapem

Joey_XD

Zavolame na omegu Foxa Muldera a Scullyovú

Joey_XD

Quote from: Joey_XD on  12.05.2010, 04:47:25
Kto mi vysvetli jednu vec.... Na ubuntu mi ide Karol perfektne, riesi problem ako ma... Ale ked skopirujem tie iste zdrojaky na omegu, prelozim cez make (preklad prebehne bez chyb), lenze pri spusteni programu Karol v jednom okamihu zastane a vypise ze narazil do steny, aj ked uz cez to niesto presiel predtym.... Uz fakt neviem co s tym je... v algorytme by nemala byt chyba ked na ubuntu to ide bez chybycky.


a to som este zabudol, ze pri tom kroku co zastane je podmienka if(frontIsClear){movek()} ... cize nechapem


Robi to este niekomu?

revelc

asi ti to nepomoze (mozno si to len zle prepisal) , ale nema tam byt?
Quoteif(frontIsClear()){movek()}
Čo môžeš urobiť dnes odlož na pozajtra a ziskaš deň voľna.

"I'm a man of simple tastes. I enjoy dynamite...and gunpowder...and gasoline! "

potototamto

ako mam zadefinovat ten postup beeprov, aby mi vypisal zaradom 123456?...mne to hodi na kazdy druhy krok...zadanie 11.

Vikinger

zadanie 11 uz tu bolo hodene takze len pohladaj a nespamuj :-) je cele spravenee tak len sooosujj:D