顺序串的定义
#define MaxSize 100 typedef struct { char data[MaxSize]; int length; }SqString;
串赋值运算算法
#include<stdio.h> #define MaxSize 100 typedef struct { char data[MaxSize]; int length; }SqString; void Assign(SqString *s,char str[]) { int i=0; while(str[i]!='\0')//遍历str的所有字符 { s->data[i]=str[i]; i++; } s->data[i]='\0'; s->length=i; } void main() { int i; SqString s; char str[]="abcdfff"; Assign(&s,str); //for(i=0;i<s.length;i++) //{ printf("%s\n",s.data); //} }