Click here to Skip to main content
15,885,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
#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;
}*/
Posted
Comments
CPallini 29-Jan-16 4:04am    
Why don't you use C++ std containers (string and vector)?
Member 12202551 29-Jan-16 4:10am    
sorry i am new , can u please explain more

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.
C++
printf("name of player: %s",max[i].name );

Tip: before you use the struct, you better set all to zero.
C++
memset( &max, 0, sizeof(gusty) * 10 ); //all struct at startup


Take the time to understand and learn all: IT IS WORTH IT!!! :-)
 
Share this answer
 
Comments
Member 12202551 29-Jan-16 4:26am    
thanks
i see all the tutorials but i am doing c++ and we dont use these
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << ".\n";
return 0;
count and arrows so i am confused
can u please explain more
The print function doesn't need the entire array but only the gusty struct.

void playerprint(struct gusty *item)
{
printf("%s\n",item->name);
}
 
Share this answer
 
v2
Comments
Member 12202551 30-Jan-16 20:08pm    
thanks for that
but that is not working for me :(
Michael Haephrati 31-Jan-16 6:00am    
Try now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900