Its quite bizarre to me, more I'm trying to friendly with string / character processing with C programming, they are showing their envy to me.
I was/am need to split a / any big osm file to three parts, NODE, WAY and RELATION. You can do that by giving line number range to program. But I want to get the line number automatically.
This was seems very easy, just counting the new line till getting required string, i.e. <way id=
So I wrote,
char way_compare[] = "<way id=";
FILE *fp = fopen("Kiel.osm", "r");
char ckchr[10];
int count_line=1;
char chr = getc(fp);
while(chr != EOF)
{
if(chr == '\n')
{ count_line++;
fgets(ckchr, 10, fp);
if(!strcmp(way_compare,ckchr))
{ break; }
}
chr = getc(fp);
}
printf("Searched: %s found at %d\n",way_compare,count_line);