暑假作业1.2

#include  <stdio.h>
#define    N    5
typedef struct  student {
  long  sno;
  char  name[10];
  float  score[3];
} STU;
void fun(char  *filename, STU  n)
{ FILE  *fp;
/**********found**********/
  fp = fopen(filename, "rb+");
/**********found**********/
  fseek(fp, -(long)sizeof(STU), SEEK_END);
/**********found**********/
  fwrite(&n, sizeof(STU), 1, fp);
  fclose(fp);
}
void main()
{ STU  t[N]={ {10001,"MaChao", 91, 92, 77}, {10002,"CaoKai", 75, 60, 88},
             {10003,"LiSi", 85, 70, 78},    {10004,"FangFang", 90, 82, 87},
             {10005,"ZhangSan", 95, 80, 88}};
  STU  n={10006,"ZhaoSi", 55, 70, 68}, ss[N];
  int  i,j;      FILE  *fp;
  fp = fopen("student.dat", "wb");
  fwrite(t, sizeof(STU), N, fp);
  fclose(fp);
  fp = fopen("student.dat", "rb");
  fread(ss, sizeof(STU), N, fp);
  fclose(fp);
  printf("\nThe original data :\n\n");
  for (j=0; j<N; j++)
  {  printf("\nNo: %ld  Name: %-8s      Scores:  ",ss[j].sno, ss[j].name);
     for (i=0; i<3; i++)  printf("%6.2f ", ss[j].score[i]);
     printf("\n");
  }
  fun("student.dat", n);
  printf("\nThe data after modifing :\n\n");
  fp = fopen("student.dat", "rb");
  fread(ss, sizeof(STU), N, fp);
  fclose(fp);
  for (j=0; j<N; j++)
  {  printf("\nNo: %ld  Name: %-8s      Scores:  ",ss[j].sno, ss[j].name);
     for (i=0; i<3; i++)  printf("%6.2f ", ss[j].score[i]);
     printf("\n");
  }
}
   


#include <stdio.h>
#include <stdlib.h>
typedef  struct  aa
{  int  data;
   struct  aa  *next;
} NODE;
NODE *Creatlink(int  n, int  m)
{  NODE  *h=NULL, *p, *s;
   int  i;
/**********found***********/
   p=(NODE *)malloc(sizeof(NODE));
   h=p;
   p->next=NULL;
   for(i=1; i<=n; i++)
   {  s=(NODE *)malloc(sizeof(NODE));
      s->data=rand()%m;      s->next=p->next;
      p->next=s;             p=p->next;
   }
/**********found***********/
   return  h;
}
void outlink(NODE  *h)
{  NODE  *p;
   p=h->next;
   printf("\n\nTHE  LIST :\n\n  HEAD ");
   while(p)
   {  printf("->%d ",p->data);
      p=p->next;
   }
   printf("\n");
}
void main()
{  NODE  *head;
   head=Creatlink(8,22);
   outlink(head);
}


 

#include<string.h>
#include<stdio.h>
#define N 80
int fun(char *s)
{
  int i,n=0;
  for(i=0;s[i]!='\0';i++)
	  if(s[i]!=' '&&(s[i]!=' '||s[i]!='\0'))
		  n++;
  return(n);
}
void main()
{ 
  FILE *wf;
  char line[N]; 
  int num=0;
  printf("Enter a string:\n "); 
  gets(line);
  num=fun(line);
  printf("The number of word is:%d\n\n ",num);
/******************************/
  wf=fopen("out.dat","w");
  fprintf(wf,"%d",fun("a big car"));
  fclose(wf);
/*****************************/
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值