Hi again,
Thanks for your cooperation and problem solved.
In C18 is not possible to assign pointer's value to a variable. In the code above I had:
Code:
startostring2=string2; -->Error
startostring is a ram variable who retain the address contained in string2 (a pointer).
Even startostring is a 16 bit value and it is able to manage the 16 bit value stored in string2, there was an Error [1131] type mismatch in assignment.
The problem is, startostring2 is a variable and string2 is a pointer.
what to do?, simple, let's startostring be a pointer.
startostring is a pointer now and, it has to be declared exactly as string was. I mean, if string2 is a char, startostring2 has to be a char. If string2 is a unsigned char, startostring2 has to be a unsigned char and so on.
If we declare string2 as a char and startofstring2 as a unsigned char, we will get the same error code: mismatch in assignment.
Well, my code, now turns into:
Code:
signed short int finds(char *string1, char *string2){
unsigned int counter1=0;
unsigned int counter2=0;
char *startostring2;
char *startostring1;
startostring2=string2;
startostring1=string1;
while(*string1!=0){
counter2=counter2+1;
string1=string1+1;
}
string1=startostring1;
while(counter1!=counter2){
if(*string2!=*string1){
string1=string1+1;
counter1=counter1+1;
}
else{
do{
string1=string1+1;
string2=string2+1;
}while((*string2==*string1)&&(*string2!=0));
if(*string2==0){
return counter1;
}
else{
counter1=string1-startostring1;
string2=startostring2;
}
}
}
return -1;
}
well, now works fine for me.
Hope it can help somebody.