C语言如何按列读取csv中的两列不知道个数的数据,并能对两个同一行的数据进行加法运算

2020-07-02 教育 199阅读
我用C语言来读取csv文件中的多行多列数据,用的是fgets和sscanf函数,想一次读取一行数据(包含多列),但是怎么也读不
出来。希望能给出解决方法。谢谢了。
我是这样用的
FILE* file;
const char *filename;
int file_ended = 0;
filename="tong.csv";
file=fopen(filename,"r");
if (file==NULL)
robot_console_printf("%s: unable to locate the %s file\n",name,filename);
fgets(l,100,file); /* 从文件中读取字符串 */
if (file_ended==0) { /* read the data from the current line... */
ni = sscanf(l,"%f, %f, %f, %f, %f, %f", &motor_position[0],&motor_position[1], &motor_position
[2],&motor_position[3],&motor_position[4],&motor_position[5]);
for(i=0;i<6;i++) /* convert to radian */
next_position[i] = motor_position[i];
for(i=0;i<6;i++)
printf("%f\n",next_position[i]);
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com