G
Gizmo
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(),iPosition,3);
the erorr will occur. However if i do
cout <<strcpy(new char,mid(newString.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(pbData(pHead) + pHead->nDataSize,
_bNoMansLandFill, nNoMansLandSize))
_RPT3(_CRT_ERROR, "DAMAGE: after %hs block (#%d) at
0x%08X.\n",
szBlockUseName[_BLOCK_TYPE(pHead->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* cStringBeingSentIn, int iPositionToStartAt, int iLength)
{
iLength = iLength - 1;
char *cNewStringBeingLookedAt = (char*)malloc(iLength+1+1);
int iCharPositionToBeStoredAt = 0;
if ((iPositionToStartAt + iLength+1) > (int)strlen(cStringBeingSentIn) )
{
return new char = "ERROR";
}
if (cStringBeingSentIn == NULL)
{
return new char = "ERROR";
}
if ( (iPositionToStartAt <0) || (iLength < 0) )
{
return new char = "ERROR";
}
if (strlen(cStringBeingSentIn) == 0)
{
return new char = "ERROR";
}
for (int iCount = iPositionToStartAt; iCount <= iPositionToStartAt +
iLength; iCount++)
{
cNewStringBeingLookedAt[iCharPositionToBeStoredAt] =
cStringBeingSentIn[iCount];
iCharPositionToBeStoredAt++;
}
cNewStringBeingLookedAt[iLength+1] = '\0';
return strcpy(new char,cNewStringBeingLookedAt) ;
}
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(),iPosition,3);
the erorr will occur. However if i do
cout <<strcpy(new char,mid(newString.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(pbData(pHead) + pHead->nDataSize,
_bNoMansLandFill, nNoMansLandSize))
_RPT3(_CRT_ERROR, "DAMAGE: after %hs block (#%d) at
0x%08X.\n",
szBlockUseName[_BLOCK_TYPE(pHead->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* cStringBeingSentIn, int iPositionToStartAt, int iLength)
{
iLength = iLength - 1;
char *cNewStringBeingLookedAt = (char*)malloc(iLength+1+1);
int iCharPositionToBeStoredAt = 0;
if ((iPositionToStartAt + iLength+1) > (int)strlen(cStringBeingSentIn) )
{
return new char = "ERROR";
}
if (cStringBeingSentIn == NULL)
{
return new char = "ERROR";
}
if ( (iPositionToStartAt <0) || (iLength < 0) )
{
return new char = "ERROR";
}
if (strlen(cStringBeingSentIn) == 0)
{
return new char = "ERROR";
}
for (int iCount = iPositionToStartAt; iCount <= iPositionToStartAt +
iLength; iCount++)
{
cNewStringBeingLookedAt[iCharPositionToBeStoredAt] =
cStringBeingSentIn[iCount];
iCharPositionToBeStoredAt++;
}
cNewStringBeingLookedAt[iLength+1] = '\0';
return strcpy(new char,cNewStringBeingLookedAt) ;
}
Any help would be grate if any one can figure out what going on. Thanks in
adv.
Gizmo.