Click here to Skip to main content
15,891,674 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: 890818 - message dispatching Pin
Moak9-Nov-10 2:18
Moak9-Nov-10 2:18 
GeneralRe: 890818 - message dispatching Pin
ilostmyid29-Nov-10 2:31
professionalilostmyid29-Nov-10 2:31 
QuestionWM_QUERYENDSESSION Pin
Member 28830678-Nov-10 19:35
Member 28830678-Nov-10 19:35 
AnswerRe: WM_QUERYENDSESSION Pin
Sauro Viti8-Nov-10 20:55
professionalSauro Viti8-Nov-10 20:55 
QuestionTracking application crashes in 'C' Pin
coder21k8-Nov-10 19:08
coder21k8-Nov-10 19:08 
AnswerRe: Tracking application crashes in 'C' Pin
Cedric Moonen8-Nov-10 20:27
Cedric Moonen8-Nov-10 20:27 
AnswerRe: Tracking application crashes in 'C' Pin
Moak9-Nov-10 2:13
Moak9-Nov-10 2:13 
Questionconverting function float to string for sprintf Pin
rezen858-Nov-10 14:07
rezen858-Nov-10 14:07 
hi,
i'm working on a project that capture real time temperature.I managed to capture the real time temperature but when i tried to send the captured values to another device it displayed weird characters eg' ?.After which i did some research again on the codings.I found out that the software i'm using doesn't support %f and i'm required to do some conversion to it.I came up with the codes but its unable to work.Please advice.

my original codes:
C++
void loop(){
    float tmpVALUE=0;    //necessary to place it here to get temp reading
    char dataToSend[100];
    
    
  // Creating a connection to a device
  if(!BT.createConnection("0003190D102D","02"))
  {
    USB.println("");
    USB.print("--- CONNECTION -- MTU: ");
    USB.print(BT.connection_mtu[0],BYTE);
    USB.print(BT.connection_mtu[1],BYTE);
    USB.println(BT.connection_mtu[2],BYTE);    
  }
  else USB.println("Connection failed");
  
  
  tmpVALUE = SensorEvent.readValue(SENS_SOCKET5);
  
  if(tmpVALUE>0.5)
  {
    tmpVALUE=((tmpVALUE-0.5)/0.01);
  }
  else
  {
    tmpVALUE=tmpVALUE/0.01;
  }
  
  delay(100);
  XBee.print("Temperature: ");
  XBee.println(tmpVALUE);
  delay(5000);
  
  
  // obtain and sending tmpVALUE
  sprintf(dataToSend,"%f",tmpVALUE);  
  if(!BT.sendData(dataToSend)) USB.println("Data sent OK");
  else USB.println("Error while sending data");


modifed

C++
void loop()
{
    float testVal=7.3812849;    //necessary to place it here to get temp reading
    char dataToSend[100];
    char converttmpVALUE[100];
   
   
  // Creating a connection to a device
  if(!BT.createConnection("0003190D102D","02"))
  {
    USB.println("");
    USB.print("--- CONNECTION -- MTU: ");
    USB.print(BT.connection_mtu[0],BYTE);
    USB.print(BT.connection_mtu[1],BYTE);
    USB.println(BT.connection_mtu[2],BYTE);   
  }
  else USB.println("Connection failed");
 
 
  tmpVALUE = SensorEvent.readValue(SENS_SOCKET5);
 
  if(tmpVALUE>0.5)
  {
    tmpVALUE=((tmpVALUE-0.500)/0.010);
  }
  else
  {
    tmpVALUE=tmpVALUE/0.010;
  }
 
  delay(100);
  XBee.print("Temperature: ");
  XBee.println(tmpVALUE);
  delay(5000);
 
 
  // obtain tmpVALUE (changes made here)
  sprintf(dataToSend,"%s",ftoa(converttmpVALUE,testVal,4));
  char *ftoa(char *a, double f, int precision)
{
  long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};

  char *ret = a;
  long heiltal = (long)f;
  itoa(heiltal, a, 10);
  while (*a != '\0') a++;
  *a++ = '.';
  long decimal = abs((long)((f - heiltal) * p[precision]));
  itoa(decimal, a, 10);
  return ret;
}
 
  if(!BT.sendData(dataToSend)) USB.println("Data sent OK");
  else USB.println("Error while sending data");

AnswerRe: converting function float to string for sprintf Pin
KingsGambit8-Nov-10 17:08
KingsGambit8-Nov-10 17:08 
AnswerRe: converting function float to string for sprintf Pin
CPallini8-Nov-10 23:19
mveCPallini8-Nov-10 23:19 
GeneralRe: converting function float to string for sprintf Pin
rezen859-Nov-10 14:53
rezen859-Nov-10 14:53 
QuestionWhat to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE Pin
Code-o-mat8-Nov-10 9:05
Code-o-mat8-Nov-10 9:05 
AnswerRe: What to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE Pin
«_Superman_»8-Nov-10 9:37
professional«_Superman_»8-Nov-10 9:37 
GeneralRe: What to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE Pin
Code-o-mat8-Nov-10 10:04
Code-o-mat8-Nov-10 10:04 
GeneralRe: What to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE Pin
«_Superman_»8-Nov-10 10:12
professional«_Superman_»8-Nov-10 10:12 
GeneralRe: What to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE Pin
Code-o-mat8-Nov-10 21:30
Code-o-mat8-Nov-10 21:30 
Questionchar * - returning address of local variable or temporary Pin
piul8-Nov-10 5:11
piul8-Nov-10 5:11 
AnswerRe: char * - returning address of local variable or temporary Pin
Alain Rist8-Nov-10 5:23
Alain Rist8-Nov-10 5:23 
GeneralRe: char * - returning address of local variable or temporary Pin
piul8-Nov-10 5:29
piul8-Nov-10 5:29 
GeneralRe: char * - returning address of local variable or temporary Pin
Alain Rist8-Nov-10 5:59
Alain Rist8-Nov-10 5:59 
AnswerRe: char * - returning address of local variable or temporary Pin
jschell8-Nov-10 5:39
jschell8-Nov-10 5:39 
AnswerRe: char * - returning address of local variable or temporary Pin
David Crow8-Nov-10 5:40
David Crow8-Nov-10 5:40 
AnswerRe: char * - returning address of local variable or temporary Pin
Sauro Viti8-Nov-10 5:50
professionalSauro Viti8-Nov-10 5:50 
AnswerRe: char * - returning address of local variable or temporary Pin
«_Superman_»8-Nov-10 7:03
professional«_Superman_»8-Nov-10 7:03 
AnswerRe: char * - returning address of local variable or temporary Pin
tom144312-Nov-10 2:26
tom144312-Nov-10 2:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.