如何更改字符串的值 [英] How do I change the value of a string

查看:162
本文介绍了如何更改字符串的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我必须制作一个程序来加载一个足球队,有几个球员,我必须替换现有的一名球员。

这是需要制作的功能分数:

So I have to make a program which loads a footbal team,with several players,and I have to make a substitution with one of the existing plaayers.
This is the function that needs to make the sustitution:

void substitution(TEAM *team, PLAYER player1, int n)
{
	int i;
	PLAYER *player;
	for (i = 1; i <= team->numberOfPlayers; i++)
	{
		if (&player[i].jerseyNumber == n)
		{
			player[i].jerseyNumber = player1[i].jerseyNumber;
			player[i].name= player1.name;
			player[i].surname = player1.surname;
		}
	}
}

推荐答案

我真的建议你坚持面向对象的设计模式。它可以帮助您编写更清晰,更好的可重复使用的代码。



当您更换播放器而不是更改团队中的完整播放器对象时。

然后它也很简单:

I really recommand that you stick to object oriented design pattern. It helps you to write clearer and better reusable code.

When you change a player than change the complete player object in the team.
Then it also easy:
PLAYER *removed = team.players[n];//assuming players is an array and n is the index
delete removed;// free memory from object
team.players[n] = new PLAYER(sSurName,sPreName,n);//create object with constructor and  index n





请查看 Structs和指针。编译并调试它以便学习; - )



Please take a look at Structs And Pointers. Compile and debug it for learning ;-)


这篇关于如何更改字符串的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆