#include <stdio.h>
#include <stdlib.h>
#define MAX_NUM 100
typedef struct str{
char ch[MAX_NUM+1];
int length;
}*SString;
SString initSString() //字符串初始化
{
SString str=(SString)malloc(sizeof(struct str));
if(!str) {
printf("动态内存分配失败,程序退出!\n");
exit(!0);
}
str->length=0;
return str;
}
int isEmpty(SString str) //判断字符串是否为空
{
if(str->length==0)
{
return 1;
}
return 0;
}
SString strAssign(SString str,char s[]) //字符串赋值
{
int i=0;
while(s[i])
{
str->ch[++str->length]=s[i];
i++;
}
return str;
}
void printSString(SString str) //打印字符串
{
int i;
for(i=1;i<=str->length;i++)
printf("%c",str->ch[i]);
}
//int getStrLength(SString str) //获取字符串的长度
//{
// return str->length;
//}
int main()
{
SString str=initSString(),str2=initSString();
char s[100],s2[100],s3[100],s4[100];
int num;
printf("请输入字符串的数量:");
scanf("%d",&num);
for(int i=1;i<=num;i++) {
printf("请输入第%d个字符串:",i);
scanf("%s",s);
str=strAssign(str,s);
}
printf("\n打印字符串:");
printSString(str);
}
01-16
993
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)