Reset Value of an Array

Hello together,

i have an Array saved global called:
 
char Feld[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};


when my programm runs some of them are chaning to X or O. (Tic Tac Toe)
When a new round starts i have a function where i want to reset the numbers and dont let them be X or O

how can i do this?

i though it will work like that but i does not.

 
  Feld[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
1
2
3
for (int i = 1; i <= 9; i++) {
	Feld[i - 1] = i + '0';
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <numeric>
using namespace std;

void reset( char arr[], int N )
{
   iota( arr, arr + N, '1' );
}


int main()
{
   const int SQUARES = 9;
   char arr[SQUARES];

   // Whenever you want to reset...
   reset( arr, SQUARES );

   // Check
   for ( char c : arr ) cout << c;
}
memset(Feld, ' ', 9);
Topic archived. No new replies allowed.