Ich analysiere einige CSV-Daten in C für die Zwecke einer Ruby-Erweiterung. Um die Daten aus jeder Zeile zu ziehen Ich bin mit sscanf wie folgt:sscanf und strings
char* line = RSTRING_PTR(arg);
double price;
double volume_remaining;
unsigned int type_id, range, order_id, volume_entered, minimum_volume, duration, station_id, region_id, solar_system_id, jumps;
char* issued;
char* bid;
printf("I got %s\n",line);
int res = sscanf(line, "%lf,%lf,%u,%u,%u,%u,%u,%s,%s,%u,%u,%u,%u,%u", &price, &volume_remaining, &type_id, &range, &order_id, &volume_entered, &minimum_volume, bid, issued, &duration, &station_id, ®ion_id, &solar_system_id, &jumps);
printf("I matched %d values\n", res);
printf("I have price %f, vol_rem %f, type_id %d, range %d, order_id %d, vol_ent %d, min_vol %d, issued %s, bid %s, duration %d, station_id %d, region_id %d, solar_system_id %d, jumps %d, source %s \n",price, volume_remaining, type_id, range, order_id, volume_entered, minimum_volume, issued, bid, duration, station_id, region_id, solar_system_id, jumps, source); // and hash build follows below
Laufen sie produziert diese:
I got 728499.93,437.0,2032,32767,1132932560,588,1,False,2009-05-24 19:52:08.000,90,60003760,10000002,30000142,0
I matched 7 values
I have price 728499.930000, vol_rem 437.000000, type_id 2032, range 32767, order_id 1132932560, vol_ent 588, min_vol 1, issued (null), bid (null), duration -1210229476, station_id 3001, region_id 3001, solar_system_id 1, jumps -1210299816
Beachten Sie die Null-Strings. Grundsätzlich scheint es, dass sscanf aus irgendeinem Grund auf diese stolpert. Ich kann nicht herausfinden, warum ich die Dokumente gründlich gelesen habe. Irgendwelche Ideen?
Diese Frage hat nichts mit Ruby zu tun. Bitte löschen Sie den Verweis auf Ruby im Text und löschen Sie das Ruby-Tag. –