Algorithmique et Langage - Pages de Michel Deloizy - Free
Algorithmique et Langage - Pages de Michel Deloizy - Free
Algorithmique et Langage - Pages de Michel Deloizy - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Spécifications <strong>de</strong> format (pour printf <strong>et</strong> scanf) ) :<br />
% [flags[<br />
flags] ] [width[<br />
width] ] [.prec<br />
prec] ] [F|N|h|l] type<br />
[width] Eff<strong>et</strong> sur l'affichage<br />
n : affichage d'au moins n caractères, au besoin complété par<br />
<strong>de</strong>s espaces<br />
0n<br />
: affichage d'au moins n caractères, au besoin complété à<br />
gauche par <strong>de</strong>s chiffres 0<br />
* : l'argument suivant <strong>de</strong> la liste contient la spécification <strong>de</strong><br />
largeur<br />
Spécifications <strong>de</strong> format (pour printf <strong>et</strong> scanf) ) :<br />
% [flags[<br />
flags] ] [width[<br />
width] ] [.prec<br />
prec] ] [F|N|h|l] type<br />
[.prec<br />
prec] Eff<strong>et</strong> sur l'affichage<br />
aucun<br />
: précision par défaut<br />
.0 : avec d,i,o,u,x précision par défaut<br />
: avec e, E, f pas <strong>de</strong> point décimal<br />
.n : n caractères au plus<br />
* : l'argument suivant <strong>de</strong> la liste contient la précision<br />
M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />
89<br />
M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />
90<br />
Spécifications <strong>de</strong> format (pour printf <strong>et</strong> scanf) ) :<br />
% [flags[<br />
flags] ] [width[<br />
width] ] [.prec<br />
prec] ] [F|N|h|l[<br />
F|N|h|l] ] type<br />
Modificateur Comment arg est interprété<br />
F : arg est interprété comme un pointeur long<br />
N : arg est interprété comme un pointeur court<br />
h : arg est interprété comme un entier <strong>de</strong> type short pour<br />
d,i,o,u,x,X<br />
l : arg est interprété comme un entier <strong>de</strong> type long pour<br />
d,i,o,u,x,X<br />
l : arg est interprété comme un réel <strong>de</strong> type double pour<br />
e,E,f,g,G (scanf(<br />
scanf)<br />
L : arg est interprété comme un réel <strong>de</strong> type long double<br />
pour e,E,f,g,G<br />
M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />
91<br />
Copie <strong>de</strong> fichier texte<br />
#inclu<strong>de</strong><br />
<br />
#inclu<strong>de</strong><br />
<br />
#inclu<strong>de</strong><br />
<br />
void erreur(int<br />
err, const char *fmt*<br />
fmt, , ...)<br />
{<br />
va_list arg;<br />
va_start(arg<br />
arg,fmt);<br />
fprintf(st<strong>de</strong>rr<br />
st<strong>de</strong>rr,"Erreur [%d] : ",err<br />
err);<br />
vfprintf(st<strong>de</strong>rr<br />
st<strong>de</strong>rr,fmt,arg);<br />
va_end(arg<br />
arg);<br />
exit(err<br />
err);<br />
}<br />
main(int<br />
int argc, , char *argv*<br />
argv[])<br />
{<br />
FILE *fs*<br />
fs, , *fd*<br />
;<br />
int x ;<br />
if(argc<br />
argc>1)<br />
{<br />
fs=fopen<br />
fopen(argv[1],"r");<br />
if(fs<br />
fs==NULL)<br />
erreur(1,"Le fichier %s ne peut être<br />
ouvert.\n",<br />
n",argv[1]);<br />
}<br />
else fs=stdin<br />
stdin;<br />
if(argc<br />
argc>2)<br />
{<br />
fd=fopen<br />
fopen(argv[2],"w");<br />
if(fd<br />
fd==NULL)<br />
erreur(2,"Création <strong>de</strong> %s<br />
impossible.\n",<br />
n",argv[1]);<br />
}<br />
else fd=stdout<br />
stdout;<br />
while((x=<br />
((x=g<strong>et</strong>c(fs))!=EOF)<br />
if(putc<br />
putc(x, (x,fd)==EOF) erreur(3,"Erreur<br />
en écriture");<br />
fclose(fd<br />
fd);<br />
fclose(fs<br />
fs);<br />
r<strong>et</strong>urn 0;<br />
}<br />
M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />
92<br />
23