026. C语言基础

//   251.c
#include
void main()
{
   FILE *fp;
   char x;
   fp=fopen("abc.txt","r");
   while((x=fgetc(fp))!=EOF)
   {
      putchar(x);
   }
   fclose(fp);
   getch();
}
//   252.c
#include
void main(int argc,char *argv[])
{
   FILE *fp1,*fp2;
   fp1=fopen(argv[1],"rb");
   fp2=fopen(argv[2],"wb");
   while(!feof(fp1))
   {
      fputc(fgetc(fp1),fp2);
   }
   fclose(fp1);
   fclose(fp2);
   getch();
}
//  253.c
#include
void main()
{
  FILE *fp;
  int a[10]={1,2,3,4,5,6,7,8,9,10},*p;
  fp=fopen("abc.txt","wb");
  p=a;
  while(p
//   254.c
#include
void main()
{
   FILE *fp;
   int a[10],*p;
   p=a;
   fp=fopen("abc.txt","rb");
   while(p
//   255.c
#include
struct node
{
   int num;
   char name[20];
   int score;
};
void main()
{
   struct node x[3]={1,"x001",89,
                     2,"x002",98,
                     3,"x003",89},*p;
   FILE *fp;
   if((fp=fopen("abc.txt","wb"))==NULL)
   {
      printf("error");exit(1);
   }
   for(p=x;p
//  256.c
#include
struct node
{
   int num;
   char name[20];
   int score;
};
void main()
{
   struct node x[3],*p;
   FILE *fp;
   if((fp=fopen("abc.txt","rb"))==NULL)
   {
      printf("error");exit(1);
   }
   for(p=x;pnum,p->name,p->score);
   fclose(fp);
   getch();
}
//   257.c
#include
void main()
{
   FILE *fp;
   int n;
   //scanf("%d",&n);
   if((fp=fopen("abc.txt","rb"))==NULL)
     {printf("error");exit(1);}
   //putw(n,fp);
   n=getw(fp);
   printf("%d",n);
   fclose(fp);
   getch();
}
//   258.c
#include
void putfloat(float n,FILE *fp)
{
   char *a;
   int i;
   a=(char *)&n;
   for(i=0;i<4;i++)
     fputc(a[i],fp);
}
float getfloat(FILE *fp)
{
   float n;
   int i;
   char *a;
   a=(char *)&n;
   for(i=0;i<4;i++)
     a[i]=fgetc(fp);
   return n;
}
void main()
{
   float n;
   FILE *fp;
   //scanf("%f",&n);
   fp=fopen("abc.txt","rb");
   //putfloat(n,fp);
   n=getfloat(fp);
   printf("%f",n);
   fclose(fp);
   getch();
}
//   259.c
#include
void main()
{
   FILE *fp;
   char a[20];
   fp=fopen("abc.txt","r");
   fgets(a,15,fp);
   puts(a);
   getch();
}

//  260.c
#include
void main()
{
   FILE *fp;
   //char a[20];
   fp=fopen("abc.txt","w");
   fputs("how do you turn this on",fp);
   //puts(a);
   fclose(fp);
   getch();
}

你可能感兴趣的:(026. C语言基础)