cherreram
Newbie level 5
Hi,
due to my work, recently I moved from CCS to C18 and everything ok, except for one thing: I dont know how to manage pointers in C18.
Time ago I built a string search routine who worked similar to "find" python instruction.
So, I wanted to use it now, in C18, but I have -- Error [1131] type mismatch in assignment-- in return.
this is the code:
this routine search for string2 into string1 and return the position, on string1, where string2 start to match. If string2 is not contained in string1, -1 is returned.
this is the way I use it:
in MikroC or CCS it works perfect, but C18 dont.
any advice?..I know there are ram and rom pointers, but when I have to use it?
due to my work, recently I moved from CCS to C18 and everything ok, except for one thing: I dont know how to manage pointers in C18.
Time ago I built a string search routine who worked similar to "find" python instruction.
So, I wanted to use it now, in C18, but I have -- Error [1131] type mismatch in assignment-- in return.
this is the code:
Code:
signed short int finds(char *string1, char *string2){
//Funcion para buscar string2 en string1. La max. longitud de string1 y string2
// es 128 caracteres.Devuelve la posicion del inicio de string2 en string1.
//Si no lo encuentra, devuelve un -1.
//
unsigned int counter1=0;
unsigned int counter2=0;
unsigned int startostring2=0;
unsigned int startostring1=0;
startostring2=string2; //this is to hold the start address of string2 and str1
startostring1=string1; //and here is where error [1131] type begin.
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;
}
this routine search for string2 into string1 and return the position, on string1, where string2 start to match. If string2 is not contained in string1, -1 is returned.
this is the way I use it:
Code:
signed short res=0;
char Buffer[]="this is a test only";
res=finds(&Buffer,"test");
in MikroC or CCS it works perfect, but C18 dont.
any advice?..I know there are ram and rom pointers, but when I have to use it?