Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

convert convert character pointer into floating point

Please describe your question in more detail.
If you want to convert char pointer into floating point, here is a way:

char * p; float f = (float)p;
If you want to convert char into float through pointer, this is the solution:
char * cp; float f; f = *(float *)cp;
If you want to convert char pointer to float pointer, here it is:
char * cp; float * fp = (float *)cp;
 
Please describe your question in more detail.
If you want to convert char pointer into floating point, here is a way:

char * p; float f = (float)p;
If you want to convert char into float through pointer, this is the solution:
char * cp; float f; f = *(float *)cp;
If you want to convert char pointer to float pointer, here it is:
char * cp; float * fp = (float *)cp;
Thanks for your replay. I've tried this before but didn't work for my project.
 
Hello guys I need to convert convert character pointer into floating point please share the code for it.
Distance should be convert into a floating number.



Code:
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const byte ROWS = 4; /* four rows */
const byte COLS = 4; /* four columns */
/* define the symbols on the buttons of the keypads */
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},             //A - Forward
  {'4', '5', '6', 'B'},             //B - Reverse
  {'7', '8', '9', 'C'},             //* -Start Again
  {'*', '0', '#', 'D'}              //# - Emmergency STOP
};
byte rowPins[ROWS] = {10, 11, 12, 13}; /* connect to the row pinouts of the keypad */
byte colPins[COLS] = {6, 7, 8, 9};

/* initialize an instance of class NewKeypad */
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

#define Reset 14
#define sw 2
int isObstaclePin = 3; // pin for sensor input
int motor_RW_control = 4; //reverse direction
int motor_FW_control = 5; //forward direction
int isObstacle = LOW; // HIGH MEANS NO OBSTACLE
static int Gnd_Data = 0, First_Data, Second_Data, Third_Data, Fourth_Data, Fifth_Data, Sixth_Data;
int Reset_state = 0, FSW_state = 0, RSW_state = 0, First_Floor_state = 0, Second_Floor_state = 0, Third_Floor_state = 0, Fourth_Floor_state = 0, Fifth_Floor_state = 0, Sixth_Floor_state = 0;
int count = 0, check_flag, Serial_Data = 0, key_flag = 0, sw_state = 0, test_sw_state = 0, flag_init = 1, FLAG = 1, start = 0;
char Floor, *Distance, key;
static int No_Count, lastread;
int Value, flr_select = 0, Floor_Count, icursor = 0;
char *Emmergency = "EMMERGENCY BUTTON PRESSED";
int EmmergencyLen = strlen(Emmergency);
char *Resetmsg = "RESET BUTTON PRESSED";
int ResetmsgLen = strlen(Resetmsg);

void Init()
{
  while (start == 0)
  {
    sw_state = digitalRead(sw);
    if (sw_state == HIGH)
    {
      while (FLAG == 1)
      {
        Serial.print("Enter the floor count:");
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("floor count: ");
        while (1)
        {
          char customKey = customKeypad.getKey();
          Floor = customKey;
          Serial.print(Floor);
          if (customKey)
          {
            lcd.setCursor(13, 0);
            lcd.print(customKey); delay(150);
          }
          if (Floor > 0)
          {
            break;
          }
          delay(200);
        }
        Serial.print("Enter the distance:");
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("distance:");
        while (1)
        {
          char customKey = customKeypad.getKey();
          Distance = chartoint(customKey);                   //This should be converted into float number
          if (customKey)
          {
            if (customKey == '#')
            {
              lcd.print("mm"); Serial.print("mm"); delay(200);
              FLAG = 0; break;
            }
            Serial.print(customKey);
            lcd.print(customKey);
          }
        }
      }
      Serial.println("\nSelect the Motor Direcion : \n7.UP 8.DOWN");
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("7.UP");
      lcd.setCursor(0, 1);
      lcd.print("8.DOWN");

      while (1)
      {
        char customKey = customKeypad.getKey();
        if (customKey == '7')
        {
          forward_init();
          /****** RESET ******/
          //char *resetmsg = "Press Reset switch for Reset back to ground";
          //int resetlen = strlen(resetmsg);
          while (1)
          {
            Serial.println("Press Reset switch for Reset back to ground ");
            //scroll_display(resetmsg, resetlen);
            Reset_state = digitalRead(Reset);
            if (Reset_state == HIGH)
            {
              Serial.println("RESET BUTTON PRESSED");
              scroll_display(Resetmsg, ResetmsgLen);
              Serial.println("R/W Motor ON");
              reverse_init();
              return;
            }
            delay(350);
          }

            /*char *resetmsg = "Press 8 for Reset back to ground";
            int resetlen = strlen(resetmsg);
            lcd.clear();
            while (1)
            {
            scroll_display(resetmsg, resetlen);
            
            char customKey = customKeypad.getKey();
            if (customKey == '8')
            {
              reverse_init(); start = 1;
              return;
            }
            delay(350);
            }*/
          return;
        }

      }
    }
    if (start == 1)
    {
      break;
    }
  }
}
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom