I am working with openGL in C++ and while I was taking input for the vertices in a loop, I encountered a problem where the number of vertices is changing with the input of the input value, although I am not swapping the variable.
Here the variable that I am in trouble with is numPoints, I have declared it at the top with the include lines (to try to make it global, I am originally from Java). and the value changes when the input loop value changes to i == 2. I am taking two values from keyboard, x and y. The detailed code with the main function is given below.
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include "stdio.h"
int pointValx[0];
int pointValy[0];
int numPoint;
void takeInput()
{
printf("Screen Size is 0 - 400 in X and 0 - 500 in Y\n");
printf("Lab for Line and Point\n");
printf("number of lines >> \n");
scanf("%d",&numPoint); //comment this line for Line
pointValx[numPoint];
pointValy[numPoint];
printf("numPoint >> %d\n",numPoint);
for(int i = 0; i < numPoint;)
{
    int x,y;
    printf("Input for X >> %d\n", i);
    scanf("%d",&x);
    printf("numPoint >> %d\n",numPoint);
    if(x >= 0 && x <= 400)
    {
        printf("Input for Y >> %d\n", i);
        scanf("%d",&y);
        if(y >= 0 && y <= 500)
        {
            pointValx[i] = x;
            pointValy[i] = y;
            i++;
        }
        else
        {
            printf("Y value crossed the limit\n");
        }
    }
    else
    {
       printf("X value crossed the limit\n");
    }
   }
   printf("End of Input file\n");
 }
/// MAIN FUNCTION
int main(int argc, char *argv[])
{
int win;
glutInit(&argc, argv);      /* initialize GLUT system */
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(400,500);        /* width=400pixels height=500pixels */
win = glutCreateWindow("GL_LINES and Points");  /* create window */
/* from this point on the current window is win */
takeInput();
glClearColor(0.0,0.0,0.0,0.0);  /* set background to black */
gluOrtho2D(0,400,0,500);        /* how object is mapped to window */
glutDisplayFunc(displayCB);     /* set window's display callback */
glutMainLoop();         /* start processing events... */
/* execution never reaches this point */
return 0;
}
 
     
    