99

99 date:2021.2.17
在这里插入图片描述要点:
结构变量各个成员的表示方法:
*结构指针变量).成员名;或 结构指针变量 ->成员名

详细代码如下:

#include  <stdio.h>
#include  <string.h>
struct student {
  long  sno;
  char  name[10];
  float  score[3];
};
/**********found**********/
struct student* fun(struct student  *a)  //结构指针变量
{ int  i;
  a->sno = 10002;
  strcpy(a->name, "LiSi");
/**********found**********/
  for (i=0; i<3; i++) a->score[i] += 1;
/**********found**********/
  return a ;
}
void main()
{ struct student  s={10001,"ZhangSan", 95, 80, 88},  *t;
  int  i;
  printf("\n\nThe original data :\n");
  printf("\nNo: %ld  Name: %s\nScores:  ",s.sno, s.name);
  for (i=0; i<3; i++)  printf("%6.2f ", s.score[i]);
  printf("\n");
  t = fun(&s);
  printf("\nThe data after modified :\n");
  printf("\nNo: %ld  Name: %s\nScores:  ",t->sno, t->name);
  for (i=0; i<3; i++)  printf("%6.2f ", t->score[i]);
  printf("\n");
}

在这里插入图片描述在这里插入图片描述

要点: 字符串指针数组
注意输入格式-换行 \n

详细代码如下:

#include <stdio.h>
#include <string.h>
#define    N   5
#define    M   81
/**********found**********/
 char * fun(char  (*sq)[M]) //字符串指针数组   根据返回值类型可知应定义为字符型指针函数
{  int  i;     char  *sp;
   sp=sq[0];
   for(i=0;i<N;i++)
      if(strlen( sp)<strlen(sq[i]))
         sp=sq[i] ;
/**********found**********/
   return  sp;
}
void main()
{  char   str[N][M], *longest;    int   i;
   printf("Enter %d lines :\n",N);
   for(i=0; i<N; i++) gets(str[i]);
   printf("\nThe %d string  :\n",N);
   for(i=0; i<N; i++) puts(str[i]);
   longest=fun(str);
   printf("\nThe longest string :\n"); puts(longest);
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值