CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ATOF() function error

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
riz179



Joined: 06 Apr 2012
Posts: 21

View user's profile Send private message

ATOF() function error
PostPosted: Sat Apr 07, 2012 4:54 am     Reply with quote

Hey! please help,
I'm using 4.057 and the problem is the atof() function is not displaying any data it just shows 0.00
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Apr 07, 2012 5:15 am     Reply with quote

It would be helpful for you to show us the lines in your code where it is
used. Also show us the variable declarations.
_________________
Google and Forum Search are some of your best tools!!!!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Apr 07, 2012 5:38 am     Reply with quote

We need to know exactly what type and value you are passing to atof() and exactly how you are determining what the output is. A short compilable example program is usually best.
_________________
The search for better is endless. Instead simply find very good and get the job done.
riz179



Joined: 06 Apr 2012
Posts: 21

View user's profile Send private message

PostPosted: Sun Apr 08, 2012 7:48 am     Reply with quote

Thanks for quick reply,
I have checked the atof() its doing well but the problem is actually my string don't get the value and remains empty, although there is no error. Below I'm posting the lines in which I am putting values in string. key and key[i] both are defined char and global, but the key[i] remains null.
Code:

#ifdef(__PCH__)
#include <pic18f452>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#endif
#define use_portb_kbd TRUE
#include <kbd.c>
#include <stdio.h>
#include <stdlib.h>
#include <lcd.c>
void keypad(void);
unsigned char adcchk=1;
char key;
char key1[100];
unsigned long adc;
float volts,presr,x ;
void main()
{
lcd_init();
kbd_init();
SET_TRIS_B(0xff);
port_b_pullups(true);
keypad();
lcd_putc("\f L");
delay_ms(300);
printf(lcd_putc,"\f %s",key);
x = atof(key1);
printf(lcd_putc,"%f",x);
}

void keypad(void)
{
 int i=0;
 while (true) {
      key=kbd_getc();
      if(key!=0)
        if(key=='*')
       {
            lcd_putc('\f');
            break;
       }
       else
       { if(key=='#')
      {  lcd_putc('.');
         
      }
        else
      {   lcd_putc(key);                             
         
      }
      key1[i]=key;
       }
      i++;
   }
   
   
  }


Last edited by riz179 on Sun Apr 08, 2012 9:20 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sun Apr 08, 2012 9:07 am     Reply with quote

Several things that might/do apply:
Show the declaration of 'key'. Is space actually being allocated by your declaration.
Remember a 'string' (which is what atof wants), needs to be _null terminated_. Nothing in this code is doing this....
Tidy your layout. makes it much easier to read.
Think about 'limits'. What happens if somebody keeps on typing?.
Remember the string for atof, needs the decimal point, as well as the display.

Code:

void keypad(void) {
 int i=0;

 while (i<MAXINPUTLEN) {
      key=kbd_getc();
      if(key!=0) {
         if(key=='*') {
            lcd_putc('\f');
            key[i]='\0'; //terminate the string
            return; //and exit
         }
         if(key=='#') {
            lcd_putc('.');
            key[i++]='.'; //string needs decimal point as well
        }
        else {
           lcd_putc(key);                             
           key[i++]=key;
        }
     }
  }
  key[i-1]='\0'; //terminate the overlength string   
}


Assuming 'MAXINPUTLEN', is defines as the maximum size of the string.

Can your kbd_getc, actually return a null character?. If not, the first test is pointless. If it can, what does this mean?. Timeout?. If so, you should exit tidily, rather than just keeping looping.

Best Wishes
riz179



Joined: 06 Apr 2012
Posts: 21

View user's profile Send private message

PostPosted: Sun Apr 08, 2012 12:47 pm     Reply with quote

@Ttelmah..,,
thanks man, got it working...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group