This seems a lot like you have coded before you have figured out what you are going to do. So let me point out a number of strange things that you may have overlooked.
First you initialize the board to 1,2,3, etc... e.g.
for(int y=0; y<n; y++)
for(int x=0; x<n; x++)
game_board[x][y] = value++;
Surely at the start of a game you are going to use say 0 to represent no counter, -1 for black and 1 for white. So you want to initialize the board to zero. By setting each point to a value, that is only used when you write out the board [and makes it almost impossible for the user to see the real game], you have made your life very very difficult.
Now you ask the poor used to enter the number based on the total position on the board. That is ok, but surely the coordinates would be better.
Now to calculate if you have a line of 5. Well first thing is you ONLY need to check
each of the positions from the point that you entered a new counter. Therefore,
you only have to check (at most) 8 directions. However, you do have to note that
a line can be formed up to 4 additional counters away from the point.
So the obvious way is to check from the point with a continuous addition: I will demonstrate the idea with a horrizontal forward direction line, and you can code the rest.
int posX; // Position X of new piece
int posY // Initial value
int sum(grid[posX][posY]);
// ....
// The test is
// (a) the line is not longer than 5 but includes the new piece
// (b) the sum is either +5 or -5 based on the played piece
for(int i=0;i<4 && sum==(i+1)*grid[posX][posY];i++)
{
sum+=grid[posX+i];
}
if (sum==5*grid[posX][posY])
winner();
You are going to have to deal with the edge condition. You may like wrap around, you may like the grid array to be bigger than the playing board, to avoid the test, or you make want to deal with the boundaries.