Итак, у меня есть небольшая ошибка. Почему isnt printf отображает вторую строку?Printf не отображает строку
printf("Player 1: "); //asks the players names
fgets(name1, 30, stdin);
printf("Player 2: ");
fgets(name2, 30, stdin);
fulfil(table);
player=choose_player();
shows(table);
int i;
for (i=0, count=player; i<9; i++)
{
if (count==1)
printf("It's your turn, %s \n", name1);
else
printf("It's your turn, %s \n", name2);
(..) Выход:
Игрок 1: Дэвид Лопес
Игрок 2: Рубен Аморим (...)
Это ваша очередь, Дэвид Лопес
Это ваша очередь, __________
Почему он не показывает второе имя?
Спасибо!
EDIT:
Поскольку им новое для программирования, и новичок в этом форуме, не ожидайте многого от меня! : S Я оставляю здесь основную функцию (не могу опубликовать весь код, потому что он слишком большой), так что вы, ребята, можете почувствовать, что происходит.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define PLAYER1 88 //ASCII tabble 88='X'
#define PLAYER2 79 //ASCII table 79='O'
void intro();
int read();
void fulfill(int v[]);
int control (int num1, int table[]);
int control_victory(int line[]);
int choose_player();
int show(int table[]);
int main (void)
{
char name1[30], name2[30];
int table[8], num, w, player, contador, k;
intro();
printf("Player 1: "); //Asks the names
fgets(name1, 30, stdin);
printf("Player 2: ");
fgets(name2, 30, stdin);
fulfill(table);
player=choose_player();
show(table);
int i;
for (i=0, contador=player; i<9; i++)
{
if (contador==1)
printf("It's your turn, %s \n", name1);
else if (contador==2)
printf("It's your turn, %s \n", name2);
w=read();
if (w==(-1)) //if the user enters '0', the program will exit
break;
if (contador==1)
{
int verf;
k=control (w, table); //verifies if the number inserted is valid
table[k]=PLAYER1; //Inserts the char on the array
show(table); //presents a new table
verf=control_victory(table); //verifies if there is victory for the player 1
if (verf==1) //
{
printf("\n%s won the game!\n", name1);
return 0;
}
else if (verf==3)
printf("\n Draw!\n");
contador++;
}
else if (contador==2) //Same here applies for player 2
{
int verf;
k=control (w, table);
table[k]=PLAYER2;
show(table);
verf=control_victory(table);
if (verf==2)
{
printf("\n%s won the game!\n", name2);
return 0;
}
else if (verf==3)
printf("\n Draw!\n");
contador--;
}
}
return 0;
}
Как 'name1' и' name2' определено? – alk
Также вы должны попробовать самостоятельно отладить свой код. О том, как это сделать, вы можете прочитать следующее: http://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – alk
Недостаточно кода, пожалуйста, отправьте свою полную функцию с помощью определений , –