任何人都可以帮助我....如何在函数的帮助下从这段代码打印名称 [英] can anyone help me in this please .... how to print names from this code with help of a function
本文介绍了任何人都可以帮助我....如何在函数的帮助下从这段代码打印名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include stdafx.h
#include< stdio.h>
#include< stdlib.h>
#include< time.h>
#include< string.h>
typedef struct
{
int stop;
char name [ 10 ];
}阵风;
gusty max [ 20 ];
int no_of_players;
int main( void )
{
printf( 请输入玩家编号 - );
scanf_s( %d,& no_of_players);
for ( int i = 0 ; i < no_of_players; i ++)
{
printf( 播放器名称 - );
scanf_s( %s,& max [i] .name, 10 ); // 想要在帮助下打印这些扫描的名称一个函数
printf( no of stops - );
scanf_s( %d,& max [i] .stop);
}
return 0 ;
}
/ * /
void playerprint(int x,name [])
{
printf(name%s \ n,& max [x] .name,10);
x = x + 1;
} * /
解决方案
如果您了解printf函数及其格式说明符,则非常容易。但这是一个广泛的领域:所以这里有一些教程。
printf( 播放器名称:%s,max [i]。 name);
提示:在使用struct之前,最好将all设置为零。
memset (& max, 0 , sizeof (gusty)* 10 ); // 启动时的所有结构
花时间了解并学习所有:这是值得的! : - )
print函数不需要整个数组,只需要阵风。
void playerprint(struct gusty * item)
{
printf(%s\ n,item-> name);
}
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
typedef struct
{
int stop;
char name[10];
} gusty;
gusty max[20];
int no_of_players;
int main(void)
{
printf("please enter the no of players - ");
scanf_s("%d", &no_of_players);
for (int i = 0; i < no_of_players; i++)
{
printf("name of player - ");
scanf_s("%s", &max[i].name, 10);// want to print these scanned names with the help of a function
printf("no of stops - ");
scanf_s("%d", &max[i].stop);
}
return 0;
}
/*/
void playerprint(int x, name[])
{
printf("name %s \n", &max[x].name, 10);
x = x + 1;
}*/
解决方案
It is very easy if you understand the printf function and its format specifier. But it is a wide area: so here is some tutorial.
printf("name of player: %s",max[i].name );
Tip: before you use the struct, you better set all to zero.
memset( &max, 0, sizeof(gusty) * 10 ); //all struct at startup
Take the time to understand and learn all: IT IS WORTH IT!!! :-)
The print function doesn't need the entire array but only the gusty struct.
void playerprint(struct gusty *item)
{
printf("%s\n",item->name);
}
这篇关于任何人都可以帮助我....如何在函数的帮助下从这段代码打印名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文