(atoi , atol , atof ). :
(string);
(atoi, atol, atof);
string (, );
() ;
; .
stdlib.h. atof math.h.
!
(
stdlib.h):
#include <stdlib.h>
#include <math.h>
string :
char *string /* */
char string [10] /*
(10 )*/
.
String , .
atof () :
[][][] [e|E [] ]
(, );
"+" "";
.
e (E) ;
( );
[ ] .
5 atoi atol ( ):
[][]
(, );
"+" "-";
, .
0 (0L atol).
, , . .
:
#include <stdlib.h> /* */
float n1; /* n1 */
int n2; /* n2 */
long n3; /* n3 */
char buf[10]; /* buf */
PoleN1>GetText(buf, 10); /* buf*/
n1=atof(buf); /* */
PoleN2>GetText(buf, 10); /* buf*/
n2=atoi(buf); /* */
PoleN3>GetText(buf, 10); /* buf*/
n3=atol(buf); /* */
n1 , n2 , n3 , buf 10 .
, PoleN1, PoleN2, PoleN3 buf, 10 . , , buf n1, n2 n3.
|
|
( ):
( Tab );
;
, ;
;
( ).
6.6. = 15.8, b = 0.365-2, i = -1.
:
#include <stdlib.h> /* */
float ,b; /* b */
int i; /* i */
char buf[12]; /* buf */
PoleA>GetText(buf, 12);/* buf*/
a=atof(buf); /* */
PoleB>GetText(buf, 12);/* b buf*/
b=atof(buf); /* */
PoleI>GetText(buf, 12); /* i buf*/
i=atoi(buf); /* */
.
6.7. [4] 1=2.1, 2=5.6, 3=7.5, 4=16.
:
#include <stdlib.h> /* */
float [4]; /* */
int i; /* */
char buf[10]; /* buf */
for(i=0; i < 4; i++)
{
PoleA>GetLine(buf, 10, i); /* (i) buf*/
a[i]=atof(buf);/* */
}
! Multiline () Want Return ( ) .
(itoa , ltoa , gcvt ) .
gcvt
. :
gcvt(, , buffer);
gcvt ;
() ;
;
buffer () ;
() ;
; .
stdlib.h.
.
.
, ( / ).
.
.
itoa / ltoa
/ .
:
|
|
(, buffer, );
(itoa, ltoa);
() / ;
buffer () ;
;
() ;
; .
stdlib.h.
.
.
'\0', .
(2¸36).
.
.
(itoa 17 , ltoa 33 ).
(, ):
#include <stdlib.h> /* */
float n1; /* n1 */
int n2; /* n2 */
long n3; /* n3 */
char buf[12]; /* buf */
gcvt(n1, 8, buf); /* n1 buf*/
PoleN1>SetText(buf); /* PoleN1*/
itoa(n2, buf, 10);/* n2 buf*/
PoleN2>SetText(buf); /* PoleN2*/
ltoa (n3, buf, 10);/* n3 buf*/
PoleN3>SetText(buf); /* PoleN3*/
n1 , n2 , n3 , buf 12 .
, , , n1, n2, n3 buf. 12 . 8 . . , , buf PoleN1, PoleN2, PoleN3.
sprintf
. .
:
sprintf(buffer, , 1 [,2,...,n]);
sprintf ( );
buffer () ;
, ;
1 n ;
,, ();
() ();
[ ] ;
; .
stdio.h.
.
.
.
.
( ) , ( ).
(buffer) .
( ):
#include <stdio.h>/* */
float n1; /* n1 */
int n2; /* n2 */
char buf[12]; /* buf */
sprintf(buf,%5.3f, n1);/* n1 buf*/
|
|
PoleN1>SetText(buf);/* PoleN1*/
sprintf(buf,%10d, n2);/* n1 buf*/
PoleN2>SetText(buf);/* PoleN1*/
n1, n2 buf , . buf PoleN1, PoleN2.
6.8. = 15.8, b = 0.365-2, i = -1.
:
#include <stdlib.h> /* */
#include <stdio.h> /* */
float ,b; /* b */
int i; /* i */
char buf[12]; /* buf */
sprintf(buf,%5.3f, ); /* buf*/
PoleA>SetText(buf); /* Pole*/
gcvt(b, 8, buf); /* buf*/
PoleB>SetText(buf); /* PoleB*/
itoa(i, buf, 10); /* buf*/
PoleI>SetText(buf); /* PoleI*/
( sprintf, gcvt, itoa), . .
= 15.8, b = 0.365-2, i = -1 :
( ), b 2 () 3 gcvt.
b ( ), .
, :
) /:
# include <iostream.h>
#include <conio.h>
main()
{
float a,b,s;
cin >>a>>b;
s = a*b;
cout <<" a= "<<a<<" b= "<<b<<" s= "<<s;
getch();
}
) (. . 6.3) :
#include<stdlib.h>
{
float a,b,s;
char buf[12];
PoleA>GetText(buf,12); /* PoleA buf */
a=atof(buf); /* */
PoleB->GetText(buf,12); /* PoleB buf */
b=atof(buf); /* b */
s=a*b;
gcvt(s, 12, buf); /* s */
PoleS->SetText(buf); /* PoleS*/
}