Very explicitely show me what it is that you want to do. Right now you have code that will take a string like this:
substr("XX01234567890AB", 2, 3)
That will produce
012
What do you wish for such code to do?
Printable View
Very explicitely show me what it is that you want to do. Right now you have code that will take a string like this:
substr("XX01234567890AB", 2, 3)
That will produce
012
What do you wish for such code to do?
now I Change the code, and make a strpos to find begin start char...
printCom1 (substr ("XX01234567890AB", 2, 3));Code:int strpos (unsigned char *pStrText, char pChar){ // Última ocorrência do caractere.
int iLen, iCont;
iLen = strlen (pStrText);
if (iLen > 0){
for (iCont=0; iCont<iLen; iCont++){
if (pStrText[iCont] == pChar)
return iCont;
}
return 0; // Não houve ocorrências
}
else { return 0; } // String Nula
}
Result: 012
........
Result:Code:#define STX 2
#define CR 13
#define LF 10
#define TAB 9
char cSTX;
char cCR;
char cLF;
char cTab;
cSTX = STX;
cCR = CR;
cLF = LF;
cTab = TAB;
.......
char cFuncao [2];
char *cPacote = malloc(pLen);
int iPosStart, iPosEnd, iPosTam;
//Separa o Pacote
iPosStart = strpos (pPacote, cSTX);
iPosStart++;
iPosEnd = strpos (pPacote, cCR);
iPosTam = iPosEnd - iPosStart;
if((iPosStart) && (iPosEnd)){
cPacote = substr(pPacote, iPosStart, iPosTam);
printCom1 ("cPacote: %s\n", cPacote);
printCom1 ("pPacote: %s\n", pPacote);
printCom1 ("iPosStart/iPosEnd/iPosTam: %d %d %d",iPosStart, iPosEnd, iPosTam);
cPacote: X34567890AB
pPacote: XX34567890AB
iPosStart/iPosEnd/iPosTam: 1 12 11
The problem is here: if((iPosStart) && (iPosEnd)){
The First Ocurrence at String, is at 0 index
And, because I'm incrementing iPosStart
thanks for all!
substr return 0
Because the first occurence of char at string
is 0
Click the link, perhaps.
where ?
The "?" was a link to a page about strstr(). A C Standard Library function that does what your homemade one does.