######代码
#include <stdio.h>
#include <string.h>
#define T = 3;//阈值,默认为3。
typedef struct
{
char first[20];
char secound[20];
char third[20];
char fourth[20];
}Result;
Result split(char str[], int, int, int, int);//此函数啊用于实现对字符串的分割。函数录入一个长字符串并将其分割为四个长度的字符串。
int main()
{
//char test[20] = "name";
Result result=split("hello word", 2, 2, 3, 3);
printf("%s", result.first);
}
Result split(char str[], int a, int b, int c, int d)//str[]为需要分割的字符串,剩下的四个int为每段的长度。
{
char fi[20];//分割后的第一段
char se[20];//分割后的第二段
char th[20];//分割后的第三段
char fo[20];//分割后的第四段
int i = 0;
for (int j = 0; j < a; j++)
{
fi[j] = str[i];
}
for (int j = 0; j < b; j++)
{
se[j] = str[i];
i++;
}
for (int j = 0; j < c; j++)
{
th[j] = str[i];
i++;
}
for (int j = 0; j < d; j++)
{
fo[j] = str[i];
i++;
}
// Result R = { "1","2","3","4" };
Result R = { fi,se,th,fo };
return R;
}
######错误截图
你这个编译器还能Result R = { fi,se,th,fo };这么写啊
把函数开头的四个数组初始化为0试试
char fi[20]={0};//分割后的第一段
char se[20]={0};;//分割后的第二段
char th[20]={0};;//分割后的第三段
char fo[20]={0};;//分割后的第四段
//
建议把结构里的四个字符数组你要初始化为0。然后在main定义result变量后,将变量作为函数的参数。