我的源代码如下:
#include <stdio.h>
int main()
{
float latitude;
float longitude;
char info[80];
int started = 0;
puts("data=[");
while (scanf("%f, %f, %79[^\n]", &latitude, &longitude, info) == 3) {
if (started)
printf(",\n");
else
started = 1;
printf("{latitude: %f, longitude: %f, info: '%s'}", latitude, longitude, info);
}
puts("\n]");
return 0;
}
我有一个名为gpsdata.csv的数据文件,内容如下:
42.363400,-71.098465,Speed = 21
42.363327,-71.097588,Speed = 23
42.363255,-71.096710,Speed = 17
我理解
./geo2json < gpsdata.csv
data=[
'},titude: 42.363400, longitude: -71.098465, info: 'Speed = 21
'},titude: 42.363327, longitude: -71.097588, info: 'Speed = 23
{latitude: 42.363255, longitude: -71.096710, info: 'Speed = 17'}
]
看起来是行末覆盖了行首,我做错了什么?
%79[^\n]
" 并不是你想象中的那样。 - Adam Liss