c言語の出力
2780 ワード
printf , , fprintf ,
printf ,fprintf
fprintf()
:int fprintf(FILE *stream,const char *format[,argument,...])
:① ASCⅡ
②
: ①fprintf( ," ", ); ②fprintf(stderr," "); :fprintf(stream,"%d %c %f",i,c,f); FILE *stream; int i; char c; float f; : , EOF。 :stdio.h =================================================== sprintf() ∶int sprintf(buf,format,arg_list) char *buf; ∶ arg_list format buf 。 ∶sprintf(buffer," ∶%s( ∶ %d/ %d/ %d)",string,cyls,head,sector); char buffer[100]; char *string=" "; int cyls,head,sector; ∶ 。 ∶stdio.h sprintf , : int sprintf(char *buffer,const char *format [, argument] ... ); , 。 , : 。 printf sprintf , “%” (format specifications) , , , 。 sprintf .... fscanf fprintf fscanf ,fprintf scanf printf , 。
fscanf fprintf , 。 :
fscanf( , , ); fprintf( , , ); :
fscanf(fp,"%d%s",&i,s);
fprintf(fp,"%d%c",j,ch);
fscanf fprintf 10.6 。 10.7 。
[ 10.7]
#include
struct stu
{
char name[10];
int num;
int age;
char addr[15];
}boya[2],boyb[2],*pp,*qq;
main()
{
FILE *fp;
char ch;
int i;
pp=boya;
qq=boyb;
if((fp=fopen("stu_list","wb+"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
printf("/ninput data/n");
for(i=0;i<2;i++,pp++)
scanf("%s%d%d%s",pp->name,&pp->num,&pp->age,pp->addr);
pp=boya;
for(i=0;i<2;i++,pp++)
fprintf(fp,"%s %d %d %s/n",pp->name,pp->num,pp->age,pp->
addr);
rewind(fp);
for(i=0;i<2;i++,qq++)
fscanf(fp,"%s %d %d %s/n",qq->name,&qq->num,&qq->age,qq->addr);
printf("/n/nname/tnumber age addr/n");
qq=boyb;
for(i=0;i<2;i++,qq++)
printf("%s/t%5d %7d %s/n",qq->name,qq->num, qq->age,
qq->addr);
fclose(fp);
}