任何人都可以告诉我如何打印这个名字? [英] Can Anyone Please Tell Me How I Can Print Name From This ?
本文介绍了任何人都可以告诉我如何打印这个名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int random();
typedef struct
{
//int no_of_games;
int stop;
char name[10];
} gusty;
gusty max[20];
//int numplayer = 0;
int no_of_players;
int xxxx;
//int stop_turn;
//char name[10];
int i;
int p,
sum;
int main(void)
{
time_t seconds;
time(&seconds);
srand((unsigned int)seconds);
printf("please enter the no of players - ");
scanf_s("%d", &no_of_players);
for (i = 0; i < no_of_players; i++)
{
printf("name of player - ");
scanf_s("%s", &max[xxxx].name, 10);
printf("no of stops - ");
scanf_s("%d", &max[xxxx].stop);
for (int t = 0; sum < max[xxxx].stop; t++)
{
p = random();
printf("random %d \n ", p);
sum = sum + p;
printf("sum = %d \n", sum);
}
}
printf("name %s ", max[xxxx].name); // want to print name here ,
// if there is two player this print name of only last player
return 0;
}
int random()
{
return rand() % 6 + 1;
}
推荐答案
您永远不会初始化xxxx
变量。正如Jochen所建议的那样,你可能应该使用i
而不是xxxx
。
在循环结束时你可以替换
You never initialize thexxxx
variable. As suggested by Jochen, probably you should usei
instead ofxxxx
.
at the end of the loop you could replace
Quote:
printf(name% s,max [xxxx] .name); //想在这里打印名称
printf("name %s ", max[xxxx].name); // want to print name here
与
with
if (no_of_players > 0)
printf("name %s\n", max[no_of_players-1].name);
这篇关于任何人都可以告诉我如何打印这个名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文