Atoi and atof usage

Source: Internet
Author: User
[Arrangement] when reading files by functions such as atoi and ITOA in the Linux kernel, if we want to get the int type, such
 
Read from "/sys/devices/platform/LCD-backlight/LEDs/LCD-backlight/brightness", obviously we want to be int type
However, when calling the read system, the char type is read from the file stream. Therefore, it must be converted to an int type after reading the data. This requires atoi.
 
Be sure to include the header file # include <stdlib. h>
 
 
Here are the usage of atoi and atof.
#include" stdio. H "# include" stdlib. H "Main () {char * P =" 1234567 "; int X; X = atoi (p); printf (" % D \ n ", x);} If char * P =" 1234.567 "is written, x = atof (p); C language library function name: atoi function: converts a string to an integer. name Source:  abbreviation of array to integer.    Function Description: atoi () scans the nptr parameter string, if the first character is neither a number nor a plus or minus sign, zero is returned. Otherwise, type conversion is started. If a non-digit or Terminator \ 0 is detected, the conversion is stopped and the integer number is returned. Prototype: int atoi (const char * nptr); header file to be used: # include 
   
     while atof converts a string to a float value 
   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.