Hello,
I have a relatively straight through program where I collect some integer data and pass it to an external file. The problem that I have is that what I really need to do is to pass that value divided by another integer (255 to be more exact). I tried a couple of things such as:
fprintf(pFile,"%d/255 ",State[STATE_SONAR_0+i]);
or
fprintf(pFile,"%d ",State[STATE_SONAR_0+i]/255);
but that is NOT giving me the right output (the value of State[STATE_SONAR_0] divided by 255). Any idea of how I can implement it? Below is my complete program. Thank you.
r.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "Nclient.h"
void turn_front_sonar_on(void)
{
int sn_order[16] = {0,2,4,6,8,10,12,14};
conf_sn(50, sn_order);
conf_tm(15);
}
/*
* main
*/
main(void)
{
FILE *pFile;
int i;
connect_robot(1, MODEL_SCOUT2, "/dev/ttyS0", 38400);
pFile = fopen ("log_in.txt","a");
/* turn on the front sonars */
turn_front_sonar_on();
/* the loop */
while(1)
{
gs();
i = 0;
do
{
fprintf(pFile,"%d ",State[STATE_SONAR_0+i]);
i=i+2;
} while (i < 16);
fprintf(pFile,"%d ",State[STATE_VEL_TRANS]);
fprintf(pFile,"%d\n",State[STATE_VEL_STEER]);
fprintf(pFile,"_D: ");
}
return(0);
}