#include <stdio.h>
#include <stdlib.h>
//78
void main(void)
{
char *string = "0xFF";
char *stop; //pointer value to the conversion end position can use this to the length of the converted digits
int radix;
long value;
radix = 16;
value = strtol(string, &stop, radix);
printf("%d characters have been converted\n", stop - string);
printf("The converted value of the hexadecimal %s is %ld\n", string, value);
}
long int strtol(const char *str, char **endptr, int base) converts the initial part of the string in str to a long int value according to the given base, which must be between 2 and 36 inclusive or be the special value 0.
Parameters
- str − This is the string containing the representation of an integral number.
- endptr − This is the reference to an object of type char*, whose value is set by the function to the next character in str after the numerical value.
- base − This is the base, which must be between 2 and 36 inclusive, or be the special value 0.
Return Value
This function returns the converted integral number as a long int value, else zero value is returned.
'C programming' 카테고리의 다른 글
[atof] Converting a string to real number 1 (0) | 2021.08.20 |
---|---|
[strtoul] converting a string to an integer (0) | 2021.08.20 |
[atol] Converting a string to an integer 2 (0) | 2021.08.20 |
[Simple Problems] Converting a string to an integer 1 (atoi) (0) | 2021.08.20 |
[Simple Problems] Formatting a string (sprintf) (0) | 2021.08.20 |