繁体   English   中英

将值从一个char数组存储到另一个char数组

[英]storing the values from one char array to another char array

我写了这段代码:

shuffledteamnames[8][80]; // global
winningteamnames[8][80]; // global
int main()
{
    if (team1 > team2)
    {
        cout << shuffledteamnames[index1] << " beat the " << shuffledteamnames[index2] << " " << team1 << "-" << team2 << " in a game 1." << endl;
        winningteamnames[WINTEAMcounter] = shuffledteamnames[index1];
    }
    else if (team1 < team2) // index1 = 0, index2 = 1, WINTEAMcounter = 0
    {
        cout << shuffledteamnames[index2] << " beat the " << shuffledteamnames[index1] << " " << team1 << "-" << team2 << " in a game 1." << endl;
        winningteamnames[WINTEAMcounter] = shuffledteamnames[index2];
    }
}

shuffledteamnames的输出如下所示:

Trojans
Bruins
Bears
Trees
Ducks
Beavers
Huskies
Cougars

我正在尝试创建一个竞争支架,在该支架中,我将每一轮的获胜者都放入char数组winningteamnames 我知道这些是2D char数组,因此我需要将数据输入到两个参数中,但是我不确定该怎么做。 如果您有任何疑问,请让我知道,我非常感谢您提供的所有帮助。

使用strncpy()

strncpy( winningteamnames[WINTEAMcounter]
       , shuffledteamnames[index1]
       , sizeof winningteamnames[WINTEAMcounter]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM