Stack around the variable 'Output' was corrupted

This is a discussion on Stack around the variable 'Output' was corrupted within the C Programming forums, part of the General Programming Boards category; I have the following code which can compile, build and run, however, stack around the variable 'Output' was corrupted and ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Stack around the variable 'Output' was corrupted

    I have the following code which can compile, build and run, however, stack around the variable 'Output' was corrupted and the PrintTable function is unable to produce the output I want.Please refer to the output.gif where the last Input Signals are different from the 1st and 2nd set of Input Signals ??

    Thank you.

    insert
    Code:
    #include <stdio.h>
    
    void InputSignal(int size, float *pInput);
    void FilterProcess (int size, float *pInput, float *pOutput);
    void PrintTable(int size, float *pInput, float *pOutput);
    
    void main(void)
    {
    	int size;
    	float Input[20], Output[20], *pInput, *pOutput;
    
    	printf("Enter the total number of digital signals to be processed :");
    	scanf("%d", &size);
    	
    	pInput=Input;
    	pOutput=Output;
    	InputSignal(size, &pInput);
    	FilterProcess(size, &pInput, &pOutput);
    	PrintTable(size, &pInput, &pOutput);
    
    }
    
    void InputSignal(int size, float *pInput)
    {
        int i;
    	
    	printf("Enter the %d digital signals :", size);
    	
    	for (i=0;i<size; i++)
    	{
    		scanf("%f", (pInput+i));
    		
    	}
       
    	printf("Signal No      Input Signals\n");
        printf("---------      -------------\n");
    	
    	for (i=0; i<size; i++)
    		printf("%d%20.2f\n", i+1, pInput[i]);
    }
    
    void FilterProcess (int size, float *pInput, float *pOutput)
    {
    	int i;
    	
    	printf("Signal No      Input Signals     Output Signals\n");
    	printf("---------      -------------     --------------\n");
    		
    	for (i=0; i<size; i++)
    	{
    		if (i==0) 
    			pOutput[i]=pInput[i];	
    		else {		
    			if (i==size-1)
    			{
    				pOutput[i]=pInput[i];
    				
    			}
    		   else pOutput[i]=(pInput[i-1] + pInput[i] + pInput[i+1])/3.0;
    			
    		}
    	printf("%5d%18.2f%18.2f\n", i+1, *(pInput+i), *(pOutput+i));
    	
    	} 
    }
    
    
    void PrintTable(int size, float *pInput, float *pOutput)
    {
       int i;
    
       printf("Signal No      Input Signals     Output Signals\n");
       printf("---------      -------------     --------------\n");
      
        
      for (i=0; i<size; i++){
    	  printf("%5d%18.2f%18.2f\n", i+1, pInput[i], pOutput[i]);
       }
    }
    Attached Images Attached Images  

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    &pInput is float** while function expects float*

    You should not ignore warnings that compiler gives you
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    what do you mean by float** ?

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    Thank you for your reply and it works.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,195
    Quote Originally Posted by jacksb68 View Post
    what do you mean by float** ?
    float ** is shorthand for "a pointer to a pointer to a float".
    Right 98% of the time, and don't care about the other 3%.

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    @OP
    Never use void main(void), instead int main(void).
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. funcion runs 14 times, then program crashes
    By happyclown in forum C Programming
    Replies: 9
    Last Post: 03-03-2009, 10:58 PM
  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. Need Help with Stack
    By trongsi in forum C++ Programming
    Replies: 9
    Last Post: 05-23-2006, 04:14 PM
  4. Stringy Sums
    By bumfluff in forum C++ Programming
    Replies: 14
    Last Post: 05-15-2006, 01:52 AM
  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