代码如下
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int msg_deal(char *msg_src, char *msg_done[],char *str)//返回切割了多少次
{
msg_done[0] = msg_src;
int i = 0;
while((msg_done[i] = strtok(msg_done[i], ",")) && ++i);
return i;
}
int main(int argc, char const *argv[])
{
char msg_src[]="+CMGR:REC UNREAD,+8613466630259,98/10/01,18:22:11+00,ABCdefGHI";
char *msg_done[28] = {NULL};
char *str = NULL;
int num = msg_deal(msg_src, msg_done, str);
*(msg_done[3]+strlen(msg_done[3])-3) = '\0';
/*
char * ret = strstr(msg_done[3], "+");
if (ret != NULL)
{
*ret = '\0';
}
else
{
printf("ret is NULL\n");
}
*/
printf("%s\n", msg_done[0]);
printf("%s\n", msg_done[1]);
printf("%s\n", msg_done[2]);
printf("%s\n", msg_done[3]);
printf("%s\n", msg_done[4]);
return 0;
}
运行结果如下