Skip to content

Instantly share code, notes, and snippets.

@jphastings
Created December 5, 2009 20:02
Show Gist options
  • Select an option

  • Save jphastings/249839 to your computer and use it in GitHub Desktop.

Select an option

Save jphastings/249839 to your computer and use it in GitHub Desktop.
Finds the most recent known location from a person's twitter user_timeline.
// Just a snippet!
typedef struct {
float latitude;
float longitude;
int age;
} Location;
// The file should be a twitter user_timeline
Location FindGeo(FILE *f) {
char *str = "<georss:point>";
int s_pos;
int c_pos;
char *string;
char ccnt; //char count
Location position;
position.age = -1;
s_pos = -1;
c_pos = 0;
string = malloc(strlen(str));
while (!feof(f)) {
if (c_pos == 0)
for (ccnt = 1; ccnt <= strlen(str); ccnt++)
if (!feof(f))
string[ccnt - 1] = getc(f);
if (c_pos != 0)
if (!feof(f)) {
for (ccnt = 0; ccnt <= strlen(str) - 2; ccnt++)
string[ccnt] = string[ccnt + 1];
string[strlen(str) - 1] = getc(f);
}
if (strcmp(string, str) == 0) {
s_pos = c_pos;
fscanf(f,"%f %f",&position.latitude,&position.longitude);
position.age = 0;
break;
}
c_pos++;
}
return(position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment