Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
The country I live in doesn't use English, so I might not be good at English.

i want to compile my code
but compile error happen
i don't know how to say this in english

please help me

C:\crossdev\src\mingw-w64-v3-git\mingw-w64-crt\crt\crt0_c.c undefined reference to `WinMain'

this is compile error

i cant compile
help me please

this is my whole code


C
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>


#define MAX_CUMNUM      77
#define cdouble			-15
#define CARD_NONE		-1




static int sum=0;							



static int playerOlife = 3;
static int playerTlife = 3;

int playerO;
int playerT;



int card_opened[51];		 


int cardbundle[] = {2,2,2, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 7,7,7, 8,8,8, 9,9,9, 
					10,10,10,10,10,10,10,10, 
					11,22,33,44,55,66,76,
					0,0,0,0,
					-10,-10,-10,-10,
					cdouble, cdouble, cdouble, cdouble};


void printgame(int sum, int card)
{
	
	printf("sum : %d\n", sum);
	if (card>=0)
		printf(">>putting the card %d\n",card );
	else if (card == -10)
		printf(">>putting the card %d\n",card );
	else if (card == cdouble)
		printf(">>putting the card X2\n" );
		
	else
	printf(">>putting the card %d\n",card );
}




void printPlayerCard(int arr[])  						
{
	
	int i;
	printf("1  2  3  4  5\n");
		for (i=0;i<5;i++)
		{
			if (arr[i] < 0 )
				
				switch (arr[i])
				
			{
				case cdouble :
					printf("%2s  ", "x2");		//곱2
					break;
				case -10 :
					 printf ("%3d  ", arr[i]); //default ?
					 break;
			}
			
			else
			printf("%2d  ", arr[i]);
		}
		
		printf("\n");
}


int cardcheck(int cardundle[],int card_opened[]) 
{
	
	int n;
	int b[] = {-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,
				-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,
				-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,
				-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,
				-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,
				-1};
	for (n=0;n<51;n++)
	{
		
		if (cardbundle[n] != b[n])
		{
			return 0;
			break;
		}
		else
		{
			
			
			return 1;
		}
    	 
}}
	

	
void getOnecard(int card[], int *num)			
{

	int a, result;
    int i, temp;
    
    result = cardcheck(cardbundle,card_opened);
    
    if (result == 0)
    {
    
				for(i=0;i<51;i++)
				{
					temp = card_opened[i];
					cardbundle[i] = temp;
					cardbundle[i] = card_opened[i];
					
				}
				
				memset(card_opened, -1, 51*sizeof(int));
				
				
		while (1)
	{	
			
		
	
		a = rand()%50;						 
		
	
	
		if (card[a] != CARD_NONE)
		
		{
			*num = card[a]; 					
			card[a] =  CARD_NONE;											
			return;
		 } 
	}}
	
	else
	
		while (1)
	{	
				
		a= rand()%50;						 
		
	
			
	
		
		if (card[a] != CARD_NONE)
		
		{
			*num = card[a]; 					
			card[a] =  CARD_NONE;										
			return;
		 } 
		
	}
			}
				
	
	
			

	
	
	
void getManycards(int card[], int arr[])		
	
	int i;
	for(i=0;i<5;i++)
	getOnecard(card, &arr[i]); 
	
												
}





int checkGameEnd(int sum)  
{
    if(sum >= MAX_CUMNUM)
    
    
	{
			printf("GAME END"); 
	
        return -1;}
    else
   		return 1;
}


void returnToOpen(int card_opened[], int num) 			

{
	int i=0;
	
	
	while (1)
	{
		
			if (card_opened[i] = CARD_NONE)
			{
				
				card_opened[i] = num;
				return;
			}
			i++;
	}
}






int drawCard(int num, int sum)
{
	
	if(num>=0)
	
	{
			sum = sum + num;}
	
		
	else
	{
		switch(num)
		{
			case cdouble :
				return cdouble;
				break;
				
			case -10:
			
			{
				if (sum>=10)
				sum = sum - 10;
				else
				sum = 0;
			}
				break;
			
		}
	}
	return 0;
}

int playerturn(int playercard[], int sum, int cardbundle[], int player)	
{
	
	
	int n, toOpen=0; 
	
		if (player == playerO)
			{
			

				printf("player1 turn! player life : %d sum : %d\n", playerOlife, sum);
				
				printPlayerCard(playercard);
		
		
				do{
				printf("input the number : ");
				scanf("%d", &n);
		
				if (n<1 || n>5)
				printf("Choose again!\n");
			
				else
				printf("No. %d \n", n);

			}while (n<1 || n>5);
			
			toOpen = drawCard(playercard[n-1], sum);
		
			printgame(sum, playercard[n-1]);
			returnToOpen(card_opened, playercard[n-1]);
			getOnecard(cardbundle,&playercard[n-1]);
				
			return toOpen; 
		
	}
	
	else if (player == playerT)
			{
			

				printf("player2 turn! player life : %d sum : %d\n", playerTlife, sum);
				printPlayerCard(playercard);
		
		
				do{
				printf("input the number : ");
				scanf("%d", &n);
		
				if (n<1 || n>5)
				printf("Choose again!\n");
			
				else
				printf("No. %d \n", n);

			}while (n<1 || n>5);
			
			toOpen = drawCard(playercard[n-1], sum);
		
			printgame(sum, playercard[n-1]);
			returnToOpen(card_opened, playercard[n-1]);
			getOnecard(cardbundle,&playercard[n-1]);
				
			return toOpen; 
		
	}
 		
 		
 		
	
int checkPlayerlife(int sum,int playerlife)
{ 										
	
	if	((sum % 11==0) && (sum < 77))
		{
				printf("Life lose! multiple of 11");
			playerlife = playerlife -1;
		}
	else if (sum >= 77)
		{
				printf("Life lose! over 77");
			playerlife = playerlife -1;}
	else
		{
				return 1;}
}



	

int main(void)
{
	srand(( int)time(NULL));
    int i,j;
    int gameCnt=0;
    
    int cardbundle[] = {2,2,2, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 7,7,7, 8,8,8, 9,9,9, 
					10,10,10,10,10,10,10,10, 
					11,22,33,44,55,66,76,
					0,0,0,0,
					-10,-10,-10,-10,
					cdouble, cdouble, cdouble, cdouble};

		int playerOcard[5];
		int playerTcard[5];				
		int trig;
		
		getManycards(cardbundle, playerOcard);
		getManycards(cardbundle, playerTcard);
		printgame(sum,0);
    //initialization
  
    
   														
 	do													
while (checkPlayerLife())		
    {
    	
    
	

	


					
    
      
        
        printf("\n\n\t [[[[[ %i'th game start!!! ]]]]]\n\n", gameCnt);
        
        
        //inner loop : one game operation//한 라운드가 inner 
        while (sum < 77 )
        {
           checkPlayerlife(sum,playerOlife);
		   playerturn(playerTcard, sum, cardbundle, playerT);
		   trig = playerturn(playerOcard, sum, cardbundle, playerO);
            if (trig == cdouble)
            		checkPlayerlife(sum,playerTlife);
            		playerturn(playerTcard, sum, cardbundle, playerT);
        			trig = playerturn(playerTcard, sum, cardbundle, playerT);
        	
        	if (trig == cdouble)
        			checkPlayerlife(sum,playerOlife);
        		
					if(sum>76)
        			break;
        			
        			else
            		playerturn(playerOcard, sum, cardbundle, playerO);
        			trig = playerturn(playerOcard, sum, cardbundle, playerO);
        			
        	
		//print card
            
            //select card
        
            //check life
            
            //move to next turn
        }
        printf("GAME END");
        gameCnt++;
        
        
        
    }  while (playerOlife == 0 || playerTlife == 0);
    
    
    
    return 0;
}}


What I have tried:

i searched for google
but 99% of C:\crossdev\src\mingw-w64-v3-git\mingw-w64-crt\crt\crt0_c.c undefined reference to `WinMain' error was C++
but i am C
i tried to include
#include <tchar.h>
but it still does not works

please help me
thank you
Posted
Updated 19-Nov-21 6:41am
v2
Comments
phil.o 19-Nov-21 12:31pm    
undefined reference to `WinMain'

This could indicate that you have created a dll project (WinMain is the entry point of a Windows dll) instead of a console application. I never used mingw, so I can't tell you how, but could you make sure you are actually working with a project whose destination is a console application?

See this answer to a similar question undefined reference to `WinMain' - C++ Forum[^] This should work for both C and C++, so don't let the fact that its talking about C++ confuse you.
You don't say what IDE, if any, you are using, so the comment in the linked solution about changing the build type from windows app to console app might be more appropriate.
 
Share this answer
 
To add to what k5054 has said, do yourself a favour and sort out your indentation: that's getting pretty random, with bits which ar indented and bits which just aren't. Pick a single indentation style, and apply it to your whole project. It makes you whole code easier to read and understand, and that means it becomes a lot easier to find problems with it. Most modern IDEs, and many modern editors can't do it automatically for you so tehre is really no excuse.

And while you are there dump all the spurious empty lines - they also make it harder to read your code, as few lines of "actual code" are visible on screen at any one time, being "pushed off screen" by useless blank lines. Double spacing (or more!) doesn't make code look "better", or "bigger" - it just makes it harder to work with.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900