在很多情况下需要将一条短信分割成多条短信,但是由于字符串中有汉字,分割的时候可能会出现乱码,自己写了分割个方法
#define SMS_SIG_MAX_LEN 10//单条短信的长度
char c[100]={0};
int func(char * str)
{
int i=0;
int sum=0;
int len = strlen(str);
if (len < SMS_SIG_MAX_LEN)
{
strcpy(c, str);
printf("%s/n",c);
return 1;
}
else
{
for(i= SMS_SIG_MAX_LEN-1; i>=0; i--)
{
if( (unsigned int)(*(str+i)) > 127)
{
sum++;
}
else
break;
}
if (sum%2)
{
strncpy(c, str, SMS_SIG_MAX_LEN-1);
printf("%s/n", c);
str = str+ SMS_SIG_MAX_LEN-1;
}
else
{
strncpy(c, str, SMS_SIG_MAX_LEN);
printf("%s/n", c);
str = str+ SMS_SIG_MAX_LEN;
}
func(str);
}
}