Help us and donate little Bitcoins to pay the server costs: 1AXLPuRUBYc1JczTW4XS65GL6oWjNP2Vt2

User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

because of the inhumane working conditions at amazon in Germany, I will offer the Amazon app no more! (ARD Reportage)


     int fprintf(FILE *stream, const char *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
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
#define MAX 60
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 );
   fclose (stream);
   return 0;

fprintf output example

  This string will be cut here 
c/stdio.h/fprintf.txt · Last modified: 2013/01/22 22:02 (external edit)

The new Question & Answer System is online and waiting for your Questions about Programming problems Impressum