glutCreateMenu adding menu items at run time.

So I want to add a menu entry for each ‘T’ in an array, but when I do the following I get this error:

“X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 12 (X_ConfigureWindow)
Value in failed request: 0x0
Serial number of failed request: 628
Current serial number in output stream: 628”

and my code is:

int menu, subadd, subrem;

subadd = glutCreateMenu(processMenuEvents);

		subrem = glutCreateMenu(processMenuEvents);

		int i = 0;
		for(i=0; i<=40; i++){
				char name[10];
				name[0] = objList[i][0];
				name[1] = objList[i][1];
			else i=41;

menu = glutCreateMenu(processMenuEvents);
	glutAddSubMenu("Add Object",subadd);
	glutAddSubMenu("Remove Object",subrem);

Now before I add anything to that array I get a very tall, incredibly thin submenu. But if I touch the submenu having added something I get that error.