I did read the faq but I don't understand the faq or the faq doesn't understand me
I'm realy having trouble with the pointing to the struct.
I tried to do something very easy, read from the struct(Both in Main & the function). and then write a character to players->symbol.
Code:
#include <stdio.h>
struct { /* Struct used to store names of 2 players and a symbol. */
char Player1[25]; /* Name of the first player */
char Player2[25]; /* Name of the second player */
char activePlayer[25]; /* Name of the active player. */
char symbol; /* symbol of theplayer eg. 'O' */
}players={"name1", "name2", "Active",'O'}; //One record players init names and O we only need 1 row since we use vars.
//pointers
struct players *player; //Player points to players.
//Prototypes
void print_person ( struct players *player );
int main( struct players *player){ //parameters for main is the pointer value leading to players
printf ( "Player1: %s\n", (*player).Player1 ); //print the value of player1 on the screen
printf ( "Player2: %s \n", player->Player2 ); //print the value of player2 on the screen(other syntax does the same thing)
printf ( "Symbol: %c\n", player->symbol ); //print the symbol on the screen.
//scanf("%c",players.symbol); //Can't do?
print_person ( &players ); //pass to another function.
return 0;
}
void print_person ( struct players *player )
{
printf ( "Name: %s\n", player->Player1 );
printf ( "Symbol: %s \n", (*player).Player2 );
}
Returns 5 errors and 1 warning:
Code:
Compiling...
game.c
\visual studio 2005\projects\game.c(18) : error C2037: left of 'Player1' specifies undefined struct/union 'players'
\visual studio 2005\projects\game.c(19) : error C2037: left of 'Player2' specifies undefined struct/union 'players'
\visual studio 2005\projects\game.c(20) : error C2037: left of 'symbol' specifies undefined struct/union 'players'
\visual studio 2005\projects\game.c(22) : warning C4133: 'function' : incompatible types - from '*__w64 ' to 'players *'
\visual studio 2005\projects\game.c(27) : error C2037: left of 'Player1' specifies undefined struct/union 'players'
\visual studio 2005\projects\game.c(28) : error C2037: left of 'Player2' specifies undefined struct/union 'players'
4OpEenRij - 5 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm doing something terrible wrong, or I implent a tought of myself totaly wrong please enlighten me :d