Corrupted variable stack?

This is a discussion on Corrupted variable stack? within the C Programming forums, part of the General Programming Boards category; Greetings again! I am getting corrupted stack variable for this piece of bolded code. (starCounter is corrupted) I've searched and ...

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    12

    Corrupted variable stack?

    Greetings again! I am getting corrupted stack variable for this piece of bolded code. (starCounter is corrupted) I've searched and couldn't find the solution.

    Code:
    int i;
    	int j;
    	int s;
    
    
    	double starCounter[18]= {0};
    	double lowestfreq = 0;
    	double frequencyChecker [18] = {0};
    	int begin = 2005;
    	int end = 2010;
    
    
    	// looking for the highest possible value in perHundredThousand
    		for(s=0;s<18;s++){
    			frequencyChecker[s] = perHundredThousand[s];
    			if(frequencyChecker[s]>lowestfreq){
    				lowestfreq = frequencyChecker[s];
    			}
    		}
    	// looking for the lowest possible value in perHundredThousand
    		for(s=0;s<18;s++){
    			frequencyChecker[s] = perHundredThousand[s];
    			if (frequencyChecker[s]<lowestfreq){
    				lowestfreq = frequencyChecker[s];	
    			}
    		}
    		
    		if(lowestfreq > 0.01){
    			
    		
    		printf("\t\t\tGraph\t\t\n");
    	printf("==========================================================\n");
    		for(i=18; i>0; --i){
    			starCounter[i]=ceil(perHundredThousand[i]/lowestfreq);
    		if (starCounter[i] > 65){
    			for(s = 18; s>0; --s){
    				starCounter[s] = ceil(starCounter[s]/2);
    		}
    		}
    		printf("%d - %d |", begin, end);
    			for(j=0;j<starCounter[j];j++){
    			printf("*");
    
    		}
    			printf("\n");
    			begin = end - 10;
    			end = end - 5;
    		}
    		}
    
    
    		else{
    			printf("No frequency greater than 0.01");
    		}
    	
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,259
    starCounter is an array of 18 elements. Valid indices are 0 to 17. Your bolded code is modifying starCounter[1] through starCounter[18]. starCounter[18] does not exist.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    12
    Ok I fixed that problem but now my chart wont print. I think I made a mistake again on one of the for loops that are commented. The first one looks for the biggest value in the perHundredThousand array, and the second one looks for the smallest value in the same array. Am I doing both correctly?

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,259
    Do you want the variable lowestFreq to hold the biggest value or the smallest value? It can't hold both at once.
    Right 98% of the time, and don't care about the other 3%.

  5. #5
    Registered User
    Join Date
    Jul 2013
    Posts
    12
    oh, the plan was to initialize it as the biggest value, then find the lowest value based on the found highest.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack around the variable 'Output' was corrupted
    By jacksb68 in forum C Programming
    Replies: 5
    Last Post: 09-08-2009, 08:55 AM
  2. Stack around the variable 'total' is corrupted
    By diyteam in forum C++ Programming
    Replies: 5
    Last Post: 03-09-2008, 11:45 PM
  3. stack around the variable corrupted
    By chintugavali in forum C++ Programming
    Replies: 2
    Last Post: 01-09-2008, 12:01 PM
  4. VC++ 2003: stack corrupted around variable
    By nocturna_gr in forum Windows Programming
    Replies: 2
    Last Post: 12-07-2007, 04:30 PM
  5. Stack around variable corrupted?
    By timmygee in forum C++ Programming
    Replies: 7
    Last Post: 12-10-2005, 07:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21