strchr syntax in C language

Status
Not open for further replies.

JaMe

Junior Member level 1
Joined
Nov 8, 2006
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Indonesia
Activity points
1,406
I've got variable like this

char buffer[]="$GPSACP: 140754.999,0714.0826S,11244.0902E,1.6,30.2,3,351.22,0.25,0.13,010707,05";

I'd like to make routine to find comma location. This is the program routine i've made.

char *FindComma(char *buffer, unsigned char n){
char m;
for (m=0; m<n; m++){
buffer=strchr(buffer, ',');
}
return buffer;
}

But it doesn't work. Any suggestion ?
 

Re: strchr problem

see teh code in main....

#include <stdio.h>

int main(void)
{
char buffer[]="$GPSACP: 140754.999,0714.0826S,11244.0902E,1.6,30.2,3,351.22,0.25,0.13,010707,05";
char *u,*w;
int pos,i=0,*vec=NULL,k=0;
w=buffer;
while(k<strlen(buffer))
{
u=strchr(w,',');
if(u!=NULL)
{
vec=(int *)realloc(vec,i+1);
vec[i++]=u-buffer;
w=u+1;
}
k++;
}
for(pos=0;pos<i;pos++)
printf("\n%d\n",vec[pos]);

}


the program print comma location (int) ....(position start in zero)

enjoy
 

    JaMe

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…