我有一个字符串,我使用strtok
d.dtype = strtok(incoming.mtext, "|");
d.threshold= strtok(NULL, "|");
d.pid = strtok(NULL, "|");
使用
printf("device type %s\n", d.dtype);
printf("device threshold %s\n", d.threshold);
printf("device pid %s\n", d.pid);
我可以看到所有内容都已正确分配。
我正在发送外发留言,我的留言结构是
struct msg_st {
long int mtype;
char mtext[BUFSIZ];
};
struct msg_st outgoing;
如何将d.pid
值复制到outgoing.mtype
?
答案 0 :(得分:1)
答案 1 :(得分:1)
要将字符串值转换为long int,可以使用
outgoing.mtype = atol(d.pid);