milan.rajik
Banned
- Joined
- Apr 1, 2013
- Messages
- 2,524
- Helped
- 540
- Reputation
- 1,078
- Reaction score
- 524
- Trophy points
- 1,393
- Activity points
- 0
Why this mikroC PRO PIC code not working?
It has to extract data between 2nd space char and 1st encounter of 'M' from there for first function call and for second function call it has to get data between 3rd space and first appearance of 'G'. It is working fine for 1st function call but dosen't work for subsequent calls.
It has to extract data between 2nd space char and 1st encounter of 'M' from there for first function call and for second function call it has to get data between 3rd space and first appearance of 'G'. It is working fine for 1st function call but dosen't work for subsequent calls.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 char teststr[] = "AF/CCT1456 12;22pp XX.XXM YY.YYG" char tempBuff[20], temp[20]; void SplitBuff(char *to, char *from, char delimit1, unsigned char delimit1Count, char delimit2, unsigned char delimit2Count, int lenBuff, char *tmpBuff){ unsigned delimit1Cnt = 0, delimit2Cnt = 0; unsigned char tmp[2]; tmp[0] = delimit1; tmp[1] = '\0'; strcpy(to, strtok(from, tmp)); while(++delimit1Cnt != delimit1Count){ strcpy(to, strtok(0, tmp)); } memset(to, '\0', lenBuff); tmp[0] = delimit2; strcpy(to, strtok(0, tmp)); while(++delimit2Cnt != delimit2Count){ strcat(to, strtok(0, tmp)); } strcpy(tmpBuff, to); } void main() { while(1){ SplitBuff(&tempBuff, &teststr, ' ', 2, 'M', 1, 20, &temp); SplitBuff(&tempBuff, &teststr, ' ', 3, 'G', 1, 20, &temp); } }
Last edited: