View previous topic :: View next topic |
Author |
Message |
JeffLewcock
Joined: 10 Apr 2007 Posts: 29
|
StrFnd Function |
Posted: Wed Jan 30, 2013 3:07 pm |
|
|
Not sure if this question is really for this forum but here goes
I need but cannot find a good description of strfnd in string.h
I'm trying to work out how it is used in this code snippet
Code: |
p1 = StrFnd(GPRMCStr, ',', 0); //find first comma
if (p1 == 6)
{
//check for valid packet:
if ( (StrFnd(GPRMCStr, 'A', p1+1) == 18) && (GPRMCStr[0]=='$')) //valid?
{
|
An example GPRMCstr is
$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
so for the first comma position 6 is true
However A is never p1+1 or 18 but code does actually work
Jeff |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jan 30, 2013 3:19 pm |
|
|
from...
$GPRMC,220516,A,5133
1st comma is at position 6
'A' is at position 14
at least that's the way I count it...
not '18'
or am I missing something here ??
hth
jay |
|
|
JeffLewcock
Joined: 10 Apr 2007 Posts: 29
|
|
Posted: Wed Jan 30, 2013 3:28 pm |
|
|
Hi Temtronic
No I dont think you're missing anything thats what I though.
I cannot find a good explanation of the strfnd function so cant see what the p1+1 bit is doing either
The code is from here
http://www.ccsinfo.com/forum/viewtopic.php?t=45827&highlight=gprmc+decode
at void GPRMC_decode(char *GPRMCStr, GPRMCInfo *RMCInfo)
and the program as a whole works
I wanted to work out how it works as I want to decode $GPGSA and $GPGSV strings as well
Jeff |
|
|
JeffLewcock
Joined: 10 Apr 2007 Posts: 29
|
|
Posted: Wed Jan 30, 2013 3:46 pm |
|
|
I made a mistake, I assumed strfnd was the same as strfind I don't think it is
as strfnd is defined in the program thus
Code: |
///////////////////////////////////////////////////////////////////////////////
// find c in s starting from pos st
int8 StrFnd(char *s, char c, size_t st)
{
int8 l;
for (l=st, s+=st ; *s != '\0' ; l++, s++)
if (*s == c)
return l;
return -1;
}
///////////////////////////////////////////////////////////////////////////////
|
Still cant work out the "18" though |
|
|
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Thu Jan 31, 2013 10:39 am |
|
|
The function StrFnd(char *s, char c, size_t st) returns the position of the character c in the string s, starting at position st (zero-base index).
Cheers |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Feb 01, 2013 12:34 am |
|
|
Where are you finding a 'strfnd' function for PIC-C?
I don't see one at all in string.h nor is it listed in the compiler help manual.
I think you want strchr which is listed in the manual.
(and if you're rolling through GPS sentences, strtok is nice too)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|