Pipe writing and receiving problem(I think)
I’m programming in C language (Linux environment) a video game called Plants vs Frogger, basically Crossy Road but with a frog and some plants that shoot + some crocodiles that swim in a central area of the map. I have to complete this game using processes whereby I use pipes to communicate between various parts of the program.
I’m having a problem trying to insert the crocodile processes… my project consists of several parts, we have the main where I recall the main processes and a control function where I manage all the processes + the functions that manage things individually (like movements ).. my idea for making these crocodiles was to create an array of processes and through a for fill this array, each of these crocodiles has characteristics: y, direction, speed and status (good and bad crocodile), I have these characteristics inserted into a character structure that I also use for the other “game characters” such as the frog and the plants. I have therefore inserted a fork called river into the main where I call a “functionRiver” function in which I will create the crocodile processes inside and fill them using a matrix, this matrix will be [8][3]? 8 are the flows of my river and 3 are: y, direction and speed which will then be passed into the following function: funcCrocodile (it is called every time a crocodile process is created in the for) where I manage the crocodile’s movements via a while(1 ) and attribute those matrix values to the character structure. The pipe is used at the beginning of the crocodile function and at the end, I write the position before and after the movements. In the control function then through two functions, one for deletion and one for printing and identification via id (a parameter of the character structure) I understand that it is the crocodile character and the deletion takes place or the position is updated and then printed. The error I detect is a stack smahing detected, so I suppose I’m passing something that I can’t pass… now I’ll load a part of the code: the main part, the two functions river and crocodile + the part of the control function. I thank in advance anyone who can help me and I specify in advance that my code worked perfectly before the inclusion of the crocodiles.
If needed, I can also send the entire project.
(the comments and names are written in Italian, if necessary I will translate everything into English).