Problem with pop-up menu

First let me say hello. I’m new here.
I’m from Slovenia, so let me apologize in advance for my poor English.
I found this forum and thought that this is the place where someone will help me with my problem.

I have a C program which numericaly solves some data for a system of underfloor heating.
After numerical part I use OpenGL (in the same .c file) to represent underfloor heating sketch (pipes in rooms) in 3D. Over each pipe I need to print some data (bitmap fonts in 3D space), which I got from numerical part of the program.

First print looks like this (part of my whole program). This part of a program is located in redraw subprogram, which is then used in glutDisplayFunc(redraw):


for(i = 0; i<npipes; i++)
{
sprintf(message1, "Cev %d", i);
sprintf(message2, "Q=%.1f l/h", q[i]);
glColor3f(1.0f, 1.0f, -0.3f);
print3D((xroom1[i]+xroom2[i])/2, (yroom1[i]+yroom2[i])/2, zroom1[i]+roomh/2, message1);
print3D((xroom1[i]+xroom2[i])/2, (yroom1[i]+yroom2[i])/2, zroom1[i]+roomh/4, message2);
}

Where print3D is this subprogram:


void print3D(float x, float y, float z, char *string)
{ 
char *c;
glRasterPos3f(x, y, z);
for (c=string; *c != '\0'; c++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *c);
}
}

After that I get this result:
First print of data

I’m happy with this print. I get two lines of font over each pipe (message1 and message 2). Now I would like to use pop-up menu to select different data for message2 (instead of q[i], I would like to print diameter[i] or length[i], depends on selection in a pop-up menu).

I tried with this subprogram (I use it in main as glutCreateMenu(selectData) ). This doesn’t work (menu works, but when I click on desired selection message2 isn’t replaced):


void selectData(int msg)
{
int i;
char message2new[50];
 
switch (msg)
{
case 1:
for(i = 0; i<npipes; i++)
{
sprintf(message2new, "fi=%d mm", diameter[i]);
strcpy(message2,message2new);
}
break;
 
case 2:
for(i = 0; i<npipes; i++)
{
sprintf(message2new, "L=%.2f m", length[i]);
strcpy(message2,message2new);
}
break;
}
}

I used this example for building my bitmap font print program: bitmap.c example @ opengl.org.

Can someone help me with this, please. I will be very greatful. I think I’m running into problems with string definitions.
Thanks!