Conversion from one data type to another data type
atoi():
atoi converts a string to int.
header file : stdlib.h
atof():
atof converts a string to a floating point
header file : stdlib.h
atol():
Converts a string to a long
header file : stdlib.h
itoa():
itoa converts an integer to a string
header file : stdlib.h
ltoa():
ltoa converts a long to a string
header file : stdlib.h
ultoa():
ultoa converts an unsigned long to a string
header file : stdlib.h
/* example atoi() */
#include <stdio.h>
#include<stdlib.h>
int main()
{
int n,n1;
// char *str = "12.67";
char str[]="12.67";
// char str[10]="12.67";
n = atoi(str);
printf("string = %s integer = %d\n", str, n);
n1=n*n;
printf("square = %d\n",n1);
return 0;
}
Output: string = 12.67 integer = 12 square = 144
/* example of atof() */
#include <stdio.h>
#include<stdlib.h>
int main()
{
float f,f1;
// char *str = "12.67";
char str[]="12.67";
f = atof(str);
printf("string = %s float = %f\n", str, f);
f1=f*f;
printf("square = %f\n",f1);
return 0;
}
Output: string = 12.67 float = 12.670000 square = 160.528900




