the "IIIIIIIIyyyy" was me just trying to copy what i saw in the debugger
when i went to look at the memory location. all the code is as follows
int InStr(char *cStringBeingLookedAt, char *cStringToCompareTo, bool
CaseSensitive)
{
char *cSubString = NULL;
int iPostion = 0;
char *tempChar = (char*)malloc(strlen(cStringBeingLookedAt) );
char *tempChar1 = (char*)malloc(strlen(cStringToCompareTo) );
if(cStringBeingLookedAt == NULL || cStringToCompareTo == NULL )
{
cSubString = NULL;
delete cSubString;
return -1;
}
//length of cStringBeingLookedAt = 0
if(strlen(cStringBeingLookedAt) == 0 )
{
cSubString = NULL;
delete cSubString;
return 0;
}
//you decide what to return
if(strlen(cStringToCompareTo) == 0)
{
cSubString = NULL;
delete cSubString;
return 0;
}
if (CaseSensitive == false)
{
for (unsigned int x = 0; x < strlen(cStringBeingLookedAt); x++)
{
tempChar[x] = char(toupper(cStringBeingLookedAt[x]));
}
for (unsigned int y = 0; y < strlen(cStringToCompareTo); y++)
{
tempChar1[y] = char( toupper(cStringToCompareTo[y]) );
}
}
//cSubString = strstr(cStringBeingLookedAt, cStringToCompareTo);
cSubString = strstr(tempChar, tempChar1); // <--------- when it comes to
here it has that extra bit on so it does not do what i want
//String not found
if(cSubString == NULL)
{
cSubString = NULL;
delete cSubString;
return -1;
}
//String found
else
{
iPostion = ((int)cSubString - (int)cStringBeingLookedAt);
cSubString = NULL;
delete cSubString;
return iPostion;
}
}
"Nils Petter Vaskinn" <no@spam.for.me.invalid> wrote in message
news:pa****************************@spam.for.me.in valid...
On Thu, 28 Aug 2003 16:48:54 +0100, Gizmo wrote:
hi there i was trying to create memory for a char dynamicaly. However
when i do this it seens to create 4 extra spaces in the veriable for stuff to
be stored.
char *tempChar = (char*)malloc(strlen(cStringBeingLookedAt) );
char *tempChar = malloc(strlen(cStringBeingLookedAt) +1);
Don't cast, leave room for '\0'
that is what im doing but when i come to look at it in debug mode it
shows as "IIIIIIIIyyyy"
How did you put those I's there? Show us all of the code.
each I = a space for a char. However it sticks these 4 y's on the end.
This leaves me a 4 char space each time and i dont' want these. i tried
to do
char *tempChar = (char*)malloc(strlen(cStringBeingLookedAt) - 4);
That's completely wrong.
Im trying to compare it with another script but i can't do
this while these extra y's are on the end.
Yes you can, if you null terminate your string properly and/or remeber
it's length.
regards
NPV