我的源代码如下:
#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'}
]
看起来线的末端以某种方式覆盖了线的开头。我做错了什么?
答案 0 :(得分:6)
您的数据文件使用Windows样式的行结尾(\r\n
;回车+换行符,而不是普通操作系统'\n
(换行符)。打印回车符,每次将光标移动到行的开头。