Does anyone know why I get the following error when my program finishes (using VC++6)?
Here's my code:Quote:
Debug Error!
Program: <path to my exe>
Module:
File: i386\chkesp.c
Line: 42
The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
Code:#include <iostream.h>
#include <conio.h>
#include <cstring>
#define PlainText "This is a test..."
void SortArray(long *InArray);
void GetCharCounts(char *TheString);
void SpitOutSorted(int UniqueChars);
struct SortedChars
{
char Character;
long CharCount;
};
SortedChars FinalArray[255];
unsigned __int8 TotalChars;
void SortArray(long *InArray)
{
bool Sorted = false;
int StartIndex = -1;
int Highest = 0;
cout<<"Sorting character list...";
while (!Sorted)
{
Highest = StartIndex;
for (int CurIndex = StartIndex + 1; CurIndex <= 255; CurIndex++)
{
if((InArray[Highest] > InArray[CurIndex] || InArray[Highest] <= 0) && InArray[CurIndex] > 0)
{
Highest = CurIndex;
}
if(InArray[Highest] == 1)
{
break;
}
}
if(Highest == StartIndex)
{
Sorted = true;
break;
}
FinalArray[StartIndex + 1].CharCount = InArray[Highest];
FinalArray[StartIndex + 1].Character = Highest;
InArray[Highest] = 0;
StartIndex++;
}
cout<<(char)9<<"Done"<<endl;
}
void GetCharCounts(char *TheString)
{
long CharCounts[255];
int UniqueChars = 0;
cout<<"Counting unique characters...";
for(int i = 0; i <= 255; i++)
{
CharCounts[i] = 0;
}
for(unsigned int CurChar = 0; CurChar < strlen(TheString) ; CurChar++)
{
if (CharCounts[TheString[CurChar]] == 0)
{
UniqueChars++;
}
CharCounts[TheString[CurChar]]++;
}
cout<<(char)9<<UniqueChars<<" unique characters found."<<endl;
SortArray(CharCounts);
}
void SpitOutSorted(int UniqueChars)
{
for (int i = 0; i < UniqueChars; i++)
{
cout<<FinalArray[i].Character<<(char)9<<(int)FinalArray[i].Character<<(char)9<<FinalArray[i].CharCount<<endl;
}
}
int main()
{
cout<<"The string which will be encoded is:"<<endl<<PlainText<<endl;
GetCharCounts(PlainText);
getch();
return 0;
}