//本例程序的功能是从文件中逐个读取字符,在屏幕上显示
#include<stdio.h>
#include<stdlib.h>
main()
{
FILE *fp;
char ch;
if((fp=fopen("C:\\学习地带\\编程\\字符入出\\Debug\\dd","rt"))==NULL)
{
printf("failure to open \n");
getch();//暂停,查看
exit(1);
}
ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
}
#include<stdio.h>
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("C:\\学习地带\\编程\\多块读取\\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;
fwrite(pp,sizeof(struct stu),2,fp);
rewind(fp);
fread(qq,sizeof(struct stu),2,fp);
printf("\n\nname\tnumber age addr\n");
for(i=0;i<2;i++,qq++)
printf("%s\t%5d%7d %s\n",qq->name,qq->num,qq->age,qq->addr);
fclose(fp);
}