大家好,我试图分配string
到一个char *
指针。以下是我的做法,但我收到了这个警告: assignment makes integer from pointer without a cast.
在 C 中处理字符串的正确原因是什么?
char* protoName = "";
if(h->extended_hdr.parsed_pkt.l3_proto==0)
*protoName = "HOPOPT";
else if(h->extended_hdr.parsed_pkt.l3_proto==1)
*protoName = "ICMP";
else if(h->extended_hdr.parsed_pkt.l3_proto==2)
*protoName = "IGMP";
else if(h->extended_hdr.parsed_pkt.l3_proto==3)
*protoName = "IGMP";
else if(h->extended_hdr.parsed_pkt.l3_proto==4)
*protoName = "IGMP";
char all[500];
sprintf(all,"IPv4','%s'",* protoName);