Atoi: A function that converts a string to the corresponding number
How decimals are converted to binary.
The decimal fraction part, multiplied by 2, if the product is less than 1, the standard is 0, continues to multiply by 2;
If the product is greater than 1, the standard is 1, the difference of the product minus 1 is multiplied by 2.
So go on until the difference is 0.
For example 0.625,→1.25, write down 0.1;
1.25-1=0.25,0.25*2=0.5, write down 0.10.
0.5*2=1,
The ∴0.625 is converted to binary 0.101.
-1.5 converts to binary -1.1.
scanf encounters the end of a space and gets () does not because it has no buffer
Methods to get the characters: scanf (), gets (), GetChar ()
printf is a row buffer, encountered \ n output, or full row output
printf and scanf are using the same buffer.
Print pointer:%p print unsigned shaping:%u print hex:%x
Converts a character type to an integral type:
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100
int My_atoi (char *src)
{
int flag = 1;
int result = 0;
if (*src = = '-')
{
flag =-1;
src++;
}
while (*src!= ' ")
{
if (*src >= ' 0 ' && *src <= ' 9 ')
{
Result = result * + (*SRC-' 0 ');
}
Else
{
Break
}
src++;
}
return result * FLAG;
}
int main ()
{
int i;
int Len;
int result = 0;
Char Src[max_size] = {0};
printf ("Please input string:\n");
Gets (SRC);
result = My_atoi (SRC);
printf ("result =%d\n", result);
return 0;
}
Converts an integer to a character type:
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 1024
char * INT2STR (int num)
{
char temp;
static char Result[max_size] = {0};
int i = 0;
int len = 0;
while (num!= 0)
{
Result[i] = (num% 10) + ' 0 ';
num = NUM/10;
i++;
}
Result[i] = ' the ';
Len = strlen (result);
for (i = 0; i < LEN/2; i++)
{
temp = Result[i];
Result[i] = result[len-1-i];
Result[len-1-I] = temp;
}
return result;
}
int main ()
{
int num;
printf ("Please input num:\n");
scanf ("%d", &num);
Char *result = INT2STR (num);
printf ("result =%s\n", result);
return 0;
}