我的源代码如下:
#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'}
]
看起来行尾以某种方式覆盖了行首。我究竟做错了什么?