Develop a structure for storing color circle data:

For example, here is the structure:

struct Krug { char cvetKr; int x, y, z; }; 

I transfer in function to structure.

  int N = 3; //количСство ΠΊΡ€ΡƒΠΆΠΊΠΎΠ² Krug* globalKrug = nullptr; EnterKrug(globalKrug, N); 

in theory, you need to do: "Create an array of colored circles . "

here is the function. Here I do not correctly accept the structure.

 void EnterKrug(Krug *globalKrug, int NN) { for(int i=0; i<=NN; i++) { scanf(&(globalKrug)[i].cvetKr); } } 

Closed due to the fact that the question’s essence is not clear to the participants by Vlad from Moscow , AK ♦ , αλΡχολυτ , aleksandr barakin , Cerbo Jan 15 '17 at 22:15 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • The meaning of the question is not clear. What you can not do? Provide a minimum verifiable code example. - Vlad from Moscow
  • it is impossible to create an array of groups correctly. There is no example checked. I do not know what. But there should be N circles with their own parameters - Oleg

2 answers 2

In C ++, you can create an array by explicitly declaring it, such as

 const size_t N = 3;//количСство ΠΊΡ€ΡƒΠΆΠΊΠΎΠ² ^^^^^ Krug globalKrug[N]; 

Or distribute it in dynamic memory. For example,

 size_t N = 3;//количСство ΠΊΡ€ΡƒΠΆΠΊΠΎΠ² Krug *globalKrug = new Krug[N]; 

Keep in mind that this clause in function

 scanf(&(globalKrug)[i].cvetKr); 

incorrect. You should at least write

 scanf( " %c", &globalKrug[i].cvetKr ); ^^^^^ 

    Besides the fact that you do not allocate memory ( @Vlad from Moscow wrote about this), you have one more discrepancy:

     int N = 3;//количСство ΠΊΡ€ΡƒΠΆΠΊΠΎΠ² 

    And then you write

     for(int i=0; i<=NN; i++) 

    As a result, the loop is performed N+1 times.

    • well, I would find out later, thank you, the problem itself is in the correct function call, I can not understand these pointers and references and the dynamic array - Oleg