Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C Printf未显示字符串_C - Fatal编程技术网

C Printf未显示字符串

C Printf未显示字符串,c,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&

我这里有个小虫子。为什么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);
printf(“玩家1:”)//问球员的名字
fgets(名称1、30、标准DIN);
printf(“玩家2:”);
fgets(名称2、30、标准DIN);
完成(表格);
player=选择_player();
显示(表格);
int i;

对于(i=0,count=player;i您的程序意味着同时只显示两个名称中的一个

如果第一个
if
为true,则
else
关键字将不起作用
但是,它应该在循环的第二个回合中起作用,当
count!=1

如何定义
name1
name2
时?您也应该尝试自己调试代码。关于如何执行后者,您可能希望阅读以下内容:代码不够,请发布您的完整函数和defines。
#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;