por stream. Si el stream est en el final de fichero, el indicador del final de fichero
para el stream es activado y fgetc retorna EOF. Si ocurre un error de lectura, el
indicador de error para el stream es activado y fgetc retorna EOF.
Ejemplo:
^
#include <stdio.h>
int main()
{
char nombre[10]="datos.dat";
FILE *fichero;
int i;
fichero = fopen( nombre, "r" );
printf( "Fichero: %s -> ", nombre );
if( fichero )
printf( "existe (ABIERTO)\n" );
else
{
printf( "Error (NO ABIERTO)\n" );
return 1;
}
fputc
int fputc ( int character, FILE * stream );
Write character to stream
Parameters
character
The int promotion of the character to be written.
The value is internally converted to an unsigned char when written.
stream
Pointer to a FILE object that identifies an output stream.
Return Value
On success, the character written is returned.
If a writing error occurs, EOF is returned and the error indicator (ferror) is set.
Example
1 /* fputc example: alphabet writer */
2 #include <stdio.h>
3
4 int main ()
5{
6 FILE * pFile;
7 char c;
8
9 pFile = fopen ("alphabet.txt","w");
10 if (pFile!=NULL) {
11
12
for (c = 'A' ; c <= 'Z' ; c++)
13
fputc ( c , pFile );
14
15
fclose (pFile);
16 }
17 return 0;
18 }
Other Versions
double _wtof(
const wchar_t *str
);
double _wtof_l(
const wchar_t *str,
_locale_t locale
);
Parameters
str
String to be converted.
locale
Locale to use.
Return Value
Each function returns the double value produced by interpreting the input characters as a
number. The return value is 0.0 if the input cannot be converted to a value of that type.
In all out-of-range cases, errno is set to ERANGE. If the parameter passed in is NULL, the
invalid parameter handler is invoked, as described in Parameter Validation. If execution is
allowed to continue, these functions set errno to EINVAL and return 0.
Remarks
These functions convert a character string to a double-precision, floating-point value.
The input string is a sequence of characters that can be interpreted as a numerical value of
the specified type. The function stops reading the input string at the first character that it
cannot recognize as part of a number. This character may be the null character ('\0' or L'\0')
terminating the string.
The str argument to atof and _wtof has the following form:
[whitespace] [sign] [digits] [.digits] [ {d | D | e | E }[sign]digits]
A whitespace consists of space or tab characters, which are ignored; sign is either plus (+)
or minus (); and digits are one or more decimal digits. If no digits appear before the
decimal point, at least one must appear after the decimal point. The decimal digits may be
followed by an exponent, which consists of an introductory letter (d, D, e, or E) and an
optionally signed decimal integer.
The versions of these functions with the _l suffix are identical except that they use the
locale parameter passed in instead of the current locale.
Generic-Text Routine Mappings
TCHAR.H routine
_tstof
atof
_ttof
atof
Requirements
Routine(s)
Required heade
atof
_atof_l
_wtof, _wtof_l
<stdlib.h> or <w
Example
This program shows how numbers stored as strings can be converted to numeric values
using the atof function.
//
//
//
//
//
crt_atof.c
This program shows how numbers stored as
strings can be converted to numeric
values using the atof function.
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
char
*str = NULL;
double value = 0;
// An example of the atof function
// using leading and training spaces.
str = " 3336402735171707160320 ";
value = atof( str );
printf( "Function: atof( \"%s\" ) = %e\n", str, value );
// Another example of the atof function
// using the 'd' exponential formatting keyword.
str = "3.1412764583d210";
value = atof( str );
printf( "Function: atof( \"%s\" ) = %e\n", str, value );
// An example of the atof function
// using the 'e' exponential formatting keyword.
str = " -2309.12E-15";
value = atof( str );
printf( "Function: atof( \"%s\" ) = %e\n", str, value );
}
Function: atof( " 3336402735171707160320 " ) = 3.336403e+021
Function: atof( "3.1412764583d210" ) = 3.141276e+210
Function: atof( " -2309.12E-15" ) = -2.309120e-012
See Also
Reference
Data Conversion
Floating-Point Support
System::Convert::ToSingle
System::Convert::ToDouble
Locale
_ecvt
_fcvt
_gcvt
setlocale, _wsetlocale
_atodbl, _atodbl_l, _atoldbl, _atoldbl_l, _atoflt _atoflt_l