[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