1 #include <stdio.h>
 2 #define MaxSize 100 //串中最多字符个数
 3 typedef struct
 4 {
 5     char data[MaxSize];//存放串字符
 6     int length; //存放串的实际长度
 7 }SqString;//顺序串类型
 8 
 9 void Assign(SqString *s,char str[])//定义一个函数
10 {
11     int i=0;
12     while (str[i]!='\0')// 遍历str的所有字符                                 数据结构串的运算算法
13     {
14         s->data[i]=str[i];                                                                         
15         i++;
16     }
17     s->data[i]='\0';
18     s->length=i;
19 }
20 void main()//主函数调用
21 {
22     SqString s;
23     char str[10]="abcde";
24     Assign(&s,str);//调用Assign函数
25     printf("%s\n",s.data);
26 }

 

相关文章:

  • 2021-05-30
  • 2022-12-23
  • 2021-12-15
  • 2021-07-28
  • 2022-12-23
  • 2021-12-09
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-07-13
  • 2021-08-04
  • 2021-05-25
  • 2021-10-21
相关资源
相似解决方案