-, ato* (..: atoi, atof ..), , , , , , , . , , buf2 "z16", , . atoi .
-, printf. .
, , . , strtol (int) . buf1 , .
!
#include <stdio.h> /* printf */
#include <stdlib.h> /* strtox */
#include <errno.h> /* error numbers */
#define BASE (10)
int main(void) {
char* errCheck;
char *buf1 = "42";
char *buf2 = "16";
char buf3[] = "69.00";
int i;
double d;
long l;
i = (int)strtol(buf1, &errCheck, BASE);
if(errCheck == buf1) {
printf("Conversion error:%s\n",buf1);
return EIO;
}
l = strtol(buf2, &errCheck, BASE);
if(errCheck == buf2) {
printf("Conversion error:%s\n",buf2);
return EIO;
}
d = strtod(buf3, &errCheck);
if(errCheck == buf3) {
printf("Conversion error:%s\n",buf3);
return EIO;
}
printf("%d\t%ld\t%lf\n", i, l, d);
return 0;
}