用fprintf()函数或fputs函数都能实现,
fprintf的声明如下:
int fprintf( FILE *stream, const char *format [, argument ]...);
用fprintf的例子如下
#include <stdio.h>
#include <process.h>
FILE *stream;
void main( void )
{
int i = 10;
double fp = 1.5;
char s[] = "this is a string";
char c = '\n';
stream = fopen( "fprintf.out", "w" );
fprintf( stream, "%s%c", s, c );
fprintf( stream, "%d\n", i );
fprintf( stream, "%f\n", fp );
fclose( stream );
system( "type fprintf.out" );
}
Output
this is a string
10
1.500000
fputs的声明为
fputs的例子如下int fputs( const char *string, FILE *stream );
/* FPUTS.C: This program uses fputs to write
* a single line to the stdout stream.
*/
#include <stdio.h>
void main( void )
{
fputs( "Hello world from fputs.\n", stdout );
}
Output
Hello world from fputs.
两个函数的详细介绍在MSDN中