Movatterモバイル変換


[0]ホーム

URL:


Logo

User Tools

Site Tools

You are here:start »c »stdio.h »fprintf

Sidebar

c:stdio.h:fprintf

fprintf

intfprintf(FILE*stream,constchar*format, ...);

Converts (according to format format) and writes output to stream stream. Number of characters written, or negative value on error, is returned.

optional flag:

- left adjust
+ always sign
0 zero pad
# Alternate form: for conversion character o, first digit will be zero, for [xX], prefix 0x or 0X to non-zero value, for [eEfgG], always decimal point, for [gG] trailing zeros not removed.

optional minimum width: if specified as *, value taken from next argument (which must be int).
optional . (separating width from precision)
optional precision: for conversion character s, maximum characters to be printed from the string, for [eEf], digits after decimal point, for [gG], significant digits, for an integer, minimum number of digits to be printed. If specified as *, value taken from next argument (which must be int).

optional length modifier:

h short or unsigned short
l long or unsigned long
L long double

conversion character:

d,i int argument, printed in signed decimal notation
o int argument, printed in unsigned octal notation
x,X int argument, printed in unsigned hexadecimal notation
u int argument, printed in unsigned decimal notation
c int argument, printed as single character
s char* argument
f double argument, printed with format [-]mmm.ddd
e,E double argument, printed with format [-]m.dddddd(e|E)(+|-)xx
g,G double argument
p void* argument, printed as pointer
n int* argument : the number of characters written to this point is written into argument
% no argument; prints %

C Sourcecode Example

/*  * fprintf example code * http://code-reference.com/c/stdio.h/fprintf  */  #include<stdio.h>/* including standard library *///#include <windows.h> /* uncomment this for Windows */ #define MAX60 int main(void){FILE* stream;char string[MAX];char c; sprintf(string,"This string will be cut here - This will not be shown");    stream=fopen("test.txt","w");fprintf(stream,"%-8.28s ",string);// -8 is minimun and after the . (in this case 28) is maximum chars freopen("test.txt","r", stream);while((c=fgetc(stream))!= EOF){printf("%c", c);} printf("\n");fclose(stream);return0;}

fprintf output example

  output:./fprintf   This string will be cut here

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/fprintf.txt · Last modified: 2024/02/16 01:05 (external edit)

Page Tools

Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
CC Attribution-Share Alike 3.0 UnportedDriven by DokuWiki
Tweet this link
ImpressumDatenschutz


[8]ページ先頭

©2009-2025 Movatter.jp