Thread: Illegal vector index problem

  1. #1
    Registered User Maiq's Avatar
    Join Date
    Aug 2002
    Posts
    10

    Illegal vector index problem

    When i try to run THIS PROGRAM
    i get this error message: Illegal vector index: 100 max index = 99
    what does this mean? how can i fix it?

    thanks,
    jason

  2. #2
    Registered User Maiq's Avatar
    Join Date
    Aug 2002
    Posts
    10
    the program is supposed to find the mode of the numbers in HERE (save the target as in the same directory as the cpp file) if you're trying to help

    -jason

  3. #3
    Registered User Maiq's Avatar
    Join Date
    Aug 2002
    Posts
    10
    i am using Metrowerks CodeWarrior IDE version 5.0.0.951
    Last edited by Maiq; 02-28-2003 at 01:49 AM.

  4. #4
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    as i quote...if you dont initialize variables..and use them they well contain junk values..look at this

    Code:
    int totalNums;
    	int mode;
    	
    	LoadStats(list, totalNums);
    	mode = FindMode(list, checkList, totalNums);
    you declare totNums, and mode as int and used them without initializing them...and in the function look at this

    Code:
    	for(loop = 0; loop < totNums; loop++)
    	{
    		checkList[list[loop]]++;		
    	}
    totNums = contain junk value..so you can loop more than the index value....

    there might be more stuff wrong with your code..but i am sorry..too lazy to check
    nextus, the samurai warrior

  5. #5
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    if list is and one dimensional array with 100 integers..and you set them all to 0 meaning they contain the value of 0 then


    Code:
    	for(loop = 0; loop < totNums; loop++)
    	{
    		checkList[list[loop]]++;		
    	}
    well just increment checkList[0] totNums time.....but since your totNums contain junk value..out of index :P give it a value!
    nextus, the samurai warrior

  6. #6
    Registered User Maiq's Avatar
    Join Date
    Aug 2002
    Posts
    10
    heh, thanks nextus. but i found the answer shortly before you posted (then went sleep... zzzZzZZZZ) I had my checkList array (one dimensional, yes) set to 100 slots and I changed it to 101 and it worked. I guess when i tried to get all the data in the array with the loops it contained too little memory slots than needed (just one more!! :P)

    Just to clarify, totalNums is initialized, since I pass by reference instead of value, and it gets it's value in the LoadArray function. And mode gets its value from FindMode function, you don't have to initialize a variable when you declare it, at least, that's what's been true in my experiences.

    Thanks for your help!

    -jason

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM