varför får jag fel? (Visual studio) "Error LNK 2019"
Tjoo swec!
har suttit och programmerat i Xcode och fått programmet att fungera. men sen när jag testar koden i Visual studio så får jag ett error vid namn "Error LNK 2019". Någon här som kan hjälpa mig?
felkoden:
1>------ Build started: Project: afdsfs, Configuration: Debug Win32 ------
1>Build started 2012-11-19 18:57:11.
1>PrepareForBuild:
1> Creating directory "C:\afdsfs\Debug\".
1>InitializeBuildStatus:
1> Creating "Debug\afdsfs.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> kiyfdykyd.cpp
1>c:\afdsfs\afdsfs\kiyfdykyd.cpp(84): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\afdsfs\afdsfs\kiyfdykyd.cpp(155): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\afdsfs\afdsfs\kiyfdykyd.cpp(203): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>kiyfdykyd.obj : error LNK2019: unresolved external symbol "int __cdecl play_again(void)" (?play_again@@YAHXZ) referenced in function _main
1>C:\afdsfs\Debug\afdsfs.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.27
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Koden:
/*
* File : nim.c
* Program : Nim game
* Author : ...
*/
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define MAX_COINS 13
const int HUMAN = 0;
const int COMPUTER = 1;
/* ------------- IO --------------- */
/*
* human_choice
* Get human choce as an int from stdin.
* Clears stdin.
* in: pile
* out: int-value in range 1-3 (and also less than pile)
*/
int human_choice(int pile);
/*
* write_winner
* Write winner as a string on stdout.
* in: Values HUMAN or COMPUTER.
* out:
*/
void write_winner( int player );
/*
* play_again
* Ask human if he/she wants to play
* another round. If 'n' or 'N' selected
* (single char) return false else true.
* Clears stdin.
* in:
* out: true or false
*/
int play_again();
/* ---------------- Logic ----------------*/
/*
* computer_choice
* Get computers choice (including some AI,
* if 4 coins or less left, function makes a
* smart choice else random).
* in: pile
* out: int-value in range 1-3 (and also less than pile)
*/
int computer_choice(int pile);
/*
* toggle
* Switches player, if HUMAN in COMPUTER out
* etc.
* in: actual player
* out: next player
*/
int toggle( int player );
/* --------------------- Utilities -------------*/
void clear_stdin();
/***************************************************
*
* MAIN
*
***************************************************/
int main()
{
int pile, /* This is how many coins we have */
player, /* Who is playing? */
n_coins, /* Number of coins taken */
forts = 0; /* Do the player want to continue?*/
srand (time(0) ); /* Setup random */
printf("Välkommen till NIM by Oskar Selberg & Johan Strand\n");
pile = MAX_COINS; /* Set start values (= init) */
player = HUMAN;
/*
* Program main loop
*/
while( forts == 0 ) {
int truth = 0;/*instead of _Bool*/
printf("Det ligger %d mynt i högen\n", pile );
if( player == HUMAN ){
n_coins = human_choice(pile);
}
else {
n_coins = computer_choice(pile);
printf("- Datorn tog %d\n", n_coins);
}
pile -= n_coins;
player = toggle( player );
if( pile <= 1 ){
write_winner( player );
printf("\navslutat spel");
truth = play_again();
if (truth == 1) {
pile = MAX_COINS;
printf("\n");
player = HUMAN;
}
else {
forts = 1;
break;
}
}
}
/*
* end main loop
*/
while ( forts == 1 ) {
printf("\n\nAvslutar spel\n");
return 0;
}
}
/******************************************************
*
* DEFINITIONS
*
******************************************************/
void clear_stdin()
{
while( getchar() != '\n' ){
;
}
}
/*hur många mynt tar spelaren*/
int human_choice(int pile) {
int n_coins = 0;
int x = 0;
printf("\nHur många mynt vill du ta?(mellan 1 och 3):");
while (x == 0) {
scanf("%i", &n_coins);
if (n_coins>3 || n_coins<0 || n_coins>=pile ) {
printf("du valde ett ogiltligt antal mynt!\nHur många mynt vill du ta?");
}
else {
x=1;
}
}
clear_stdin();
return n_coins;
}
/*hur många mynt datorn tar*/
int computer_choice(int pile) {
int n_coins = 0;
if (pile == 4) {
n_coins = 3;
}
else if (pile == 3) {
n_coins = 2;
}
else if (pile == 2) {
n_coins = 1;
}
else {
n_coins = (rand() % 3) + 1;
}
return n_coins;
}
/*skriv ut vinnaren*/
void write_winner(int player ) {
if (player == 0) {
printf("Datorn vann över dig!\n");
}
else if (player == 1) {
printf("Du vann över Datorn!\n");
}
}
/*vill spelaren spela igen*/
int play_again( int truth) {
char fort;
int x = 0;
while (x == 0) {
printf("\nvill du spela igen? Y/N: ");
scanf("%c", &fort);
if ((fort == 'Y' )||( fort == 'y' )) { /*han vill fortsätta*/
x = 1;
break;
}
else if ((fort == 'N' )|| (fort == 'n' )) { /*han vill inte fortsäta*/
x = 0;
break;
}
else {
printf("du har matat en ett okänt tecken, försök igen\n"); /*inte giltligt värde på inmatning*/
clear_stdin();
}
}
return x;
}
/*vems tur är det?*/
int toggle( int player ) {
if (player == 1) {
player = 0;
}
else {
player = 1;
}
return player;
}