真题三十四、三十五、三十六

 

//函数定义;结构体变量成员的表示方法
#include   <stdio.h>
#include   <string.h>
struct student {
  long  sno;
  char  name[10];
  float  score[3];
};
/**********found**********/
struct student fun(struct  student  a)//结构体定义函数类型struct student
{ int  i;
  a.sno = 10002;
/**********found**********/
  strcpy(a.name, "LiSi");//将结构体中姓名换成LiSi
/**********found**********/
  for (i=0; i<3; i++) a.score[i]+= 1;//将结构体中成绩加一
  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");
}

//将字符串数组中M各字符串合并组成一个字符串
void fun(char a[M][N],char *b)
{
	int k = 0;
	for (int i = 0; i < M; i++)//M个字符串,按顺序存入一个新的字符串
	{
		for (int j = 0; a[i][j] != '\0'; j++)//遍历字符串中每一个字符
				b[k++] = a[i][j];
	}
	b[k] = '\0';//重要,在字符串最后加入字符串标记符
}

 

//从字符串中找出子字符串的方法
#include  <stdlib.h>
#include  <conio.h>
#include  <string.h>
#include  <stdio.h>
#define N 80
int fun(char *s,char *t)
{ int n;
  char *p, *r;
  n=0;
  /*************found**************/
  r=t;
  while ( *s )
  {
	  p = s;
      while ( *r )
	  {
        if ( *r == *p )
        {
			r++;
			p++;
		}
        else
			break;
        if ( *r == '\0' )
			n++;
	  }
	  /*************found**************/
	  r=t;
      s++;
  }
  return  n;
}
void main()
{char a[N],b[N]; int m;
 
 printf("\nPlease enter string a: ");
gets(a);
 printf("\nPlease enter substring b: ");
gets(b);
 m=fun(a,b);
 printf("\nThe result is :m=%d\n",m);
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值