fwrite和fread问题
我想写入和读取几个参数到一个文件里,连续输出中一个结果是
[walk] Current position is (7,3,0.857969)Next Goal is (9,6) wx is (1,1,0.857969)
我想让写入的参数是7和3,真不知道怎么弄成wx is (7,3)
while(wb_robot_step(TIME_STEP) != -1) {
odometry_track_step(&ot);
int x = wtoc_x(ot.result.x);
int y = wtoc_y(ot.result.y);
float theta=ot.result.theta;
printf("Current position is (%d,%d,%f)",x,y,theta);
run();
FILE *com = NULL;
size_t lenx = 0;
//size_t leny = 0;
com =fopen("C:/Users/WYP/Desktop/midterm/controllers/communication","w+");
if (com== NULL) {
printf("Error in opening a file..");
}
lenx = fwrite(&x, sizeof(x),1, com);
//leny = fwrite(&y, sizeof(y), 1, com);
fclose(com);
printf(" wx is (%d,%d,%f)\n",lenx);
}