Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

strchr syntax in C language

Status
Not open for further replies.

JaMe

Junior Member level 1
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top