Tên hàm: atof()
Định nghĩa:
C Code:
#include <stdlib.h>
Chuỗi 'str' phải bắt đầu bằng kí tự số, nếu không sẽ bị lỗi chương trình (termination)
Ví dụ về 3 trường hợp
C Code:
#include <stdio.h> #include <stdlib.h> int main(void) { char *strA="30.4"; char *strB="17.3 thu xem dc khong?"; char *strC="Cai nay chac co loi 33.4"; double a,b,c; //c = atof(strC); <--- Dong nay convert se bi loi //printf("\nGia tri cua chuoi %s sau khi convert la %.2f",strC,c); <--- bo comment ra se co loi return 0; }