Forum
Tipps
News
Menu-Icon

FEHLERMELDUNG IN C bzw. C++ PROGRAMM

Guten Tag,
bei den folgenden Programm kriege ich 3 Fehlermeldungen...
2 Warnungen und ein Fatal Error... Compiler ist Microsoft Visual Studio 2005...

1.Fehler   3   fatal error C1075: Dateiende erreicht, bevor das zugehörige Element für das linke Element Klammer "{" in "c:\dokumente und einstellungen\mey\eigene dateien\visual studio 2005\projects\solution1\4gewinnt\4gewinnt.c(348)" gefunden wurde   c:\dokumente und einstellungen\mey\eigene dateien\visual studio 2005\projects\solution1\4gewinnt\4gewinnt.c   359   

2.Warnung   1   warning C4244: 'Funktion': Konvertierung von 'time_t' in 'unsigned int', möglicher Datenverlust   c:\dokumente und einstellungen\mey\eigene dateien\visual studio 2005\projects\solution1\4gewinnt\4gewinnt.c   208   

3.Warnung   2   warning C4244: 'Funktion': Konvertierung von 'double' in 'int', möglicher Datenverlust   c:\dokumente und einstellungen\mey\eigene dateien\visual studio 2005\projects\solution1\4gewinnt\4gewinnt.c   213   


Würde mich über eine baldige Antwort sehr freuen ! LG










#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
 
#define WIDTH  6
#define HEIGHT 6
 
 
// one position in field can be:
enum field {
   EMPTY = 0,
   PL1, // player 1 set
   PL2  // player 2 set
};
 
// functions may return:
enum result {
   INV,  // invalid position
   USED, // position already set
   WON,  // found 4 chain
   NE,   // not enough (4 chain not found)
   FULL  // all positions on field already set
};
 
 
const int field_char[3] = { ' ', 'O', '#' };
const int frame_char[2] = { '+', '-' };
const char *player_str[2] = { "computer", "human" };
 
enum field xy[WIDTH][HEIGHT]; // game-field (width x height)
int xy_count = 0; // count of positions in field xy[][] set
 
 
// description:
//    print xy[][] field on text-screen,
//    ix / width - vertical, iy / height - horizontal,
//    x numbers on top and bottom
void print_field(void)
{
   int ix, iy;
 
   putchar('\n');
 
   // top line with x numbers
   for (ix = 0; ix < WIDTH; ix++)
      printf(" %d", ix+1);
   putchar('\n');
 
   // frame top line
   for (ix = 0; ix <= WIDTH * 2; ix++)
      putchar(frame_char[ix%2]);
   putchar('\n');
 
   for (iy = 0; iy < HEIGHT; iy++)
   {
      // an iy line
      putchar('|');
      for (ix = 0; ix < WIDTH; ix++)
      {
         putchar( field_char[ xy[ix][HEIGHT-iy-1] ] );
         putchar('|');
      }
      putchar('\n');
 
   }
 
   // frame bottom line
   for (ix = 0; ix <= WIDTH * 2; ix++)
      putchar(frame_char[ix%2]);
   putchar('\n');
 
   // bottom line with x numbers
   for (ix = 0; ix < WIDTH; ix++)
      printf(" %d", ix+1);
   putchar('\n');
 
   putchar('\n');
}
 
// description:
//    search for next empty (not set by a player)
//    position of a given column, i.e. top of pile
// parameters:
//    int ix - x column, 0 <= x < WIDTH
// return:
//    next empty y position
//    -1 if ix-column full
int next_empty_y(int ix)
{
   int iy;
 
   for (iy = 0; iy < HEIGHT; iy++)
      if (xy[ix][iy] == EMPTY) // y position empty?
         return iy;
 
   return -1; // all y positions set by some player
}
 
// description:
//    check if 0 <= ix < WIDTH and
//    check if 0 <= iy < HEIGHT and
//    check if xy position is set by player one (PL1) or player two (PL2)
// parameters:
//    int player - player one (PL1) or player two (PL2)
//    int ix - x column
//    int iy - y position in x column
int xy_pl(int player, int ix, int iy)
{
   return ix >= 0 && ix < WIDTH  &&
          iy >= 0 && iy < HEIGHT &&
          xy[ix][iy] == player;
}
 
// description:
//    set given x position, if still free
// parameters:
//    int player - player one (PL1) or player two (PL2)
//    int ix - x column
// returns: a enum result value
//    INV  - invalid position
//    USED - position already set
//    WON  - found 4 chain
//    NE   - not enough (4 chain not found)
enum result place(int player, int ix)
{
   int tlbr_cnt = 0; // top-left -> bottom-right
   int tmbm_cnt = 0; // top-middle -> bottom-middle
   int mlmr_cnt = 0; // middle-left -> middle-right
   int trbl_cnt = 0; // top-right -> bottom-left
   int i, iy;
 
   // check if parameters are valid
   if ( ( player != PL1 && player != PL2 ) ||
        ix < 0 || ix >= WIDTH )
      return INV;
   // check if there is an empty position in that column
   if ((iy=next_empty_y(ix)) == -1)
      return USED;
 
   // set position
   xy[ix][iy] = player;
   xy_count++;
 
#define CHECK4(player, ix, iy, counter)   \
   for (i = 1; i <= 3; i++)               \
      if ( !xy_pl(player,ix,iy) )         \
         break;                           \
   counter += i - 1;
 
   // check for 4 in a row
   CHECK4(player, ix-i, iy-i, tlbr_cnt);
   CHECK4(player, ix+i, iy+i, tlbr_cnt);
   CHECK4(player, ix,   iy-i, tmbm_cnt);
   CHECK4(player, ix,   iy+i, tmbm_cnt);
   CHECK4(player, ix-i, iy,   mlmr_cnt);
   CHECK4(player, ix+i, iy,   mlmr_cnt);
   CHECK4(player, ix+i, iy-i, trbl_cnt);
   CHECK4(player, ix-i, iy+i, trbl_cnt);
 
   // check if there is a 4 chain
   if ( tlbr_cnt > 2 ||
        tmbm_cnt > 2 ||
        trbl_cnt > 2 ||
        mlmr_cnt > 2 )
      return WON;
 
   return NE;
}
 
// description:
//    human player plays one turn
//    get column number and place
// parameters:
//    int player - player one (PL1) or player two (PL2)
enum result human_new_pos(int player)
{
   int new_x, c;
 
   // get column number
   printf( "player #%d (%c), new pos (1-%d): ",
      player, field_char[player], WIDTH );
   new_x = (c = getchar()) - '1';
   while (c != '\n')
      c = getchar();
 
   // check if column valid
   if ( new_x < 0 || new_x >= WIDTH )
      return INV;
 
   // place
   return place(player, new_x);
}
 
// description:
//    computer player plays one turn
//    select random column number and place
// parameters:
//    int player - player one (PL1) or player two (PL2)
enum result computer_new_pos(int player)
{
   static int randomize = 1;
 
   // check if random generator initialised
   if (randomize)
   {
      // intialise random generator
      srand(time(NULL));
      randomize = 0;
   }
 
   // place to a random column
   return place(player, (double)rand() / RAND_MAX * WIDTH);
}
 
// description:
//    a player plays one turn
//    call apropriate funktion for human or computer player
// parameters:
//    int player - player one (PL1) or player two (PL2)
//    int human - 1 it is human, 0 it is computer
enum result play_new_pos(int player, int human)
{
   // check if all positions already set
   if (xy_count == WIDTH*HEIGHT)
      return FULL;
 
   // call apropriate function for the turn
   return human ?
      human_new_pos(player) :
      computer_new_pos(player);
}
 
// description:
//    initialise field xy
void init_field(void)
{
   int ix, iy;
 
   for (ix = 0; ix < WIDTH; ix++)
      for (iy = 0; iy < HEIGHT; iy++)
         xy[ix][iy] = EMPTY;
 
   xy_count = 0;
}
 
// description:
//    select play modus, i.e. who plays against whom
// parameters:
//    int human[2] - human[0] and human[1] is set to 0 or 1
//                   according to play modus
void select_modus(int human[2])
{
   int chosen, c;
 
   // get play modus
   while (1) {
      printf("\n\n"
             "select play modus:\n"
             " 1 - human vs. human\n"
             " 2 - computer vs. human\n"
             " 3 - human vs. computer\n"
             " 4 - computer vs. computer\n"
             "choose (1-4): " );
      // save play modus
      chosen = (c = getchar()) - '0';
      // flush input
      while (c != '\n')
         c = getchar();
      // check if valid play modus chosen
      if (chosen >= 1 && chosen <= 4)
         break; // and break out of loop
      else
         printf("invalid modus! select again...\n");
   }
 
   // set human[0] and human[1] to 0 or 1 depending on
   // whether the player is human or computer according to play modus
   human[0] = chosen == 1 || chosen == 3;
   human[1] = chosen == 1 || chosen == 2;
 
   printf( "player #1: %s\n", player_str[human[0]] );
   printf( "player #2: %s\n", player_str[human[1]] );
}
 
// description:
//    play 4 wins
void play(void)
{
   enum result result;
   int human[2];
 
   // get play modus
   select_modus(human);
 
   // initialise field
   init_field();
 
   // play until one player wins or till remis
   while (1)
   {
      //if (human[0])
         print_field();
 
      // player 1 turn
      do
         result = play_new_pos(PL1, human[0]);
      while ( result == INV || result == USED );
 
      // chek if player 1 won
      if (result == WON)
      {
         print_field();
         printf( "player 1 (%s) won!\n\n", player_str[human[0]] );
         break;
      }
      else if (result == FULL)
         break;
 
      //if (human[1])
         print_field();
 
      // player 2 turn
      do
         result = play_new_pos(PL2, human[1]);
      while ( result == INV || result == USED );
 
      // check if player 2 won
      if (result == WON)
      {
         print_field();
         printf( "player 2 (%s) won!\n\n", player_str[human[1]] );
         break;
      }
      else if (result == FULL)
         break;
   }
 
   // check for remis
   if (result == FULL)
   {
      print_field();
      printf("draw! no one won..");
   }
}
 
int main(int argc, char *argv[])
{
   while (1)
   {
      play();
      printf("press <enter> to continue\n"
             "press <ctrl> + <c> to quit");
      while (getchar() != '\n')
         ;
   }
 
   exit(0);









 


Antworten zu FEHLERMELDUNG IN C bzw. C++ PROGRAMM:

Hi |

Fehler 1: Wenn das dein gesamter Code ist, dann fehlt schlichtweg 'ne Klammer.

Fehler 2+3: Du konvertierst zu einem Datenformat mit geringerer Genauigkeit. Das kannst du machen, aber die Warnung wird dir vom Compiler trotzdem ausgegeben.

Übrigens kann Visual Studio Hilfen zu den ausgegebenen Compiler-Meldungen anzeigen.

greez 8)
JoSsiF

aso cool :) ne klammer :) hahaha

dankeschön und jetzt funktioniert es auch ... thanks =)

Schon bemerkenswert, wenn man dafür ein Forum bemühen muss.

2 Sachen noch:

- Du hast gerade über 350(!) Zeilen Code gepostet. Das ist weder hilfreich noch besonders originell! Beschränke dich auf relevante Codeabschnitte (in deinem Fall KEINER).
- Wenn du Code postest, dann poste den in Code-Tags!

greez 8)
JoSsiF


« Suche Programm/Bot...Pascal Units »
 

Fremdwörter? Erklärungen im Lexikon!
Tag
Ein Tag ist ein englischer Begriff und bedeutet so viel wie Etikett, Mal, Marke, Auszeichner und Anhänger. Generell ist Tag eine Auszeichnung eines Datenbetandes mit...

Internet-Zugriffsprogramm
Ein Internet-Zugriffsprogramm, auch Browser genannt, stellt Internetseiten für den Benutzer dar. Am bekanntesten ist der Microsoft Internet Explorer, gefolgt vom kos...

Programm
Siehe Software...


Alle Programme anzeigen – auch die versteckten!

Programme löschen und deinstallieren!