Printf未显示字符串

时间:2015-02-19 09:05:53

标签: c

所以,我这里有一个小虫子。为什么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:David Lopes

球员2:鲁本阿莫林 (...)

轮到你了,David Lopes

轮到你了,__________

为什么不显示第二个名字?

谢谢!

编辑:

由于我是编程新手,而且对这个论坛不熟悉,不要期待我的太多! :我离开这里的主要功能(不能发布整个代码,因为它太大了),这样你们就可以了解发生了什么。

#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;

}

1 个答案:

答案 0 :(得分:0)

您的程序只能同时显示两个名称中的一个。

如果您的第一个else为真,if关键字将无效 但是,当count != 1

时,它应该在循环的第二个转弯时起作用