hello all have been trying to write a Mid() function a bit like the one in
vb. i come to compile it and there are no errors however when i run it an
error accours and it says the program has to close. The odd thing is the
error accours after the mid function has done its job. but if i take out the
mid function the error does not accour.
i have found that if i do
cout <<mid(newString .GetString(),iP osition,3);
the erorr will occur. However if i do
cout <<strcpy(new char,mid(newStr ing.GetString() ,iPosition,3));
the erorr does not occur.
If i debug it . . im given the error message "Unhandled exception in
Main.exe: 0xc0000005: Access Violation." and it takes me to the part that
its says the error occurs.
The following If statment is where it says it is going wrong (i did not
write this code it must be part of the code that comes with c++)
if (!CheckBytes(pb Data(pHead) + pHead->nDataSize,
_bNoMansLandFil l, nNoMansLandSize ))
_RPT3(_CRT_ERRO R, "DAMAGE: after %hs block (#%d) at
0x%08X.\n",
szBlockUseName[_BLOCK_TYPE(pHe ad->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead));
The following code is my mid function code that i wrote (it all compiles
with out any errors).
char* mid(char* cStringBeingSen tIn, int iPositionToStar tAt, int iLength)
{
iLength = iLength - 1;
char *cNewStringBein gLookedAt = (char*)malloc(i Length+1+1);
int iCharPositionTo BeStoredAt = 0;
if ((iPositionToSt artAt + iLength+1) > (int)strlen(cSt ringBeingSentIn ) )
{
return new char = "ERROR";
}
if (cStringBeingSe ntIn == NULL)
{
return new char = "ERROR";
}
if ( (iPositionToSta rtAt <0) || (iLength < 0) )
{
return new char = "ERROR";
}
if (strlen(cString BeingSentIn) == 0)
{
return new char = "ERROR";
}
for (int iCount = iPositionToStar tAt; iCount <= iPositionToStar tAt +
iLength; iCount++)
{
cNewStringBeing LookedAt[iCharPositionTo BeStoredAt] =
cStringBeingSen tIn[iCount];
iCharPositionTo BeStoredAt++;
}
cNewStringBeing LookedAt[iLength+1] = '\0';
return strcpy(new char,cNewString BeingLookedAt) ;
}
Any help would be grate if any one can figure out what going on. Thanks in
adv.
Gizmo.
vb. i come to compile it and there are no errors however when i run it an
error accours and it says the program has to close. The odd thing is the
error accours after the mid function has done its job. but if i take out the
mid function the error does not accour.
i have found that if i do
cout <<mid(newString .GetString(),iP osition,3);
the erorr will occur. However if i do
cout <<strcpy(new char,mid(newStr ing.GetString() ,iPosition,3));
the erorr does not occur.
If i debug it . . im given the error message "Unhandled exception in
Main.exe: 0xc0000005: Access Violation." and it takes me to the part that
its says the error occurs.
The following If statment is where it says it is going wrong (i did not
write this code it must be part of the code that comes with c++)
if (!CheckBytes(pb Data(pHead) + pHead->nDataSize,
_bNoMansLandFil l, nNoMansLandSize ))
_RPT3(_CRT_ERRO R, "DAMAGE: after %hs block (#%d) at
0x%08X.\n",
szBlockUseName[_BLOCK_TYPE(pHe ad->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead));
The following code is my mid function code that i wrote (it all compiles
with out any errors).
char* mid(char* cStringBeingSen tIn, int iPositionToStar tAt, int iLength)
{
iLength = iLength - 1;
char *cNewStringBein gLookedAt = (char*)malloc(i Length+1+1);
int iCharPositionTo BeStoredAt = 0;
if ((iPositionToSt artAt + iLength+1) > (int)strlen(cSt ringBeingSentIn ) )
{
return new char = "ERROR";
}
if (cStringBeingSe ntIn == NULL)
{
return new char = "ERROR";
}
if ( (iPositionToSta rtAt <0) || (iLength < 0) )
{
return new char = "ERROR";
}
if (strlen(cString BeingSentIn) == 0)
{
return new char = "ERROR";
}
for (int iCount = iPositionToStar tAt; iCount <= iPositionToStar tAt +
iLength; iCount++)
{
cNewStringBeing LookedAt[iCharPositionTo BeStoredAt] =
cStringBeingSen tIn[iCount];
iCharPositionTo BeStoredAt++;
}
cNewStringBeing LookedAt[iLength+1] = '\0';
return strcpy(new char,cNewString BeingLookedAt) ;
}
Any help would be grate if any one can figure out what going on. Thanks in
adv.
Gizmo.
Comment