如何将结构名称转换为字符串,反之亦然? [英] How to convert a structure name into a string and vice versa?
本文介绍了如何将结构名称转换为字符串,反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将tsructure名称转换为字符串,反之亦然。我真的不知道如何在c中这样做。
有人可以帮我吗?
提前谢谢,
Hi,
I need to convert a tsructure name into a string and vice versa. I don''t really know how to do that in c.
Could anyone help me for that?
Thanks in advance,
推荐答案
嗨Carrow,
结构本质上是二进制对象,而不是字符串。
你只是想要结构的原始字节,还是你想要做其他事情?
乍一看,你可以使用这样的东西:
Hi Carrow,
Structures, by their nature are binary objects, not strings.
Do you just want the raw bytes of the structure, or are you trying to do something else?
At a first blush, you can use something like this:
展开 | 选择 | Wrap | 行号
首先,您需要将每个结构成员转换为字符串。
接下来你可以使用strcpy和strcat来构建你的最终字符串。
现在为了解码最后的字符串,插入每个成员之间的标记。经常使用逗号:
数据,数据,数据等...
像这样的字符串称为CSV字符串逗号分隔值。
您需要使用此标记将最终字符串分解为其成员。
First you need to convert each struct member to a string.
Next you can use strcpy and strcat to build your final string.
Now in order to decode the final string later, insert a marker between each of the members. A comma is frequently used:
data, data, data, etc...
A string like this is called a CSV string for comma-separated-values.
You will need this marker to break up the final string into the members that it was made from.
展开 | 选择 | Wrap | 行号
大家好,
非常感谢您的所有答案。
实际上,我正在研究一个函数作为参数接收结构。然后,我需要比较struct解析名称的4个首字母,这就是我需要将结构名称转换为字符串的原因。
我正在使用的结构包含一个很多成员(unsigned long,指针......),你认为唯一的方法是转换每个成员吗?
Carrow
Hi everyone,
Thanks a lot for all your answers.
Actually, I''m working on a function that receive as parameter a structure. Then, I need to compare the 4 first letters of the struct parsed name, that why I need to convert a struct name into string.
The structures I''m using, contain a lot of members (unsigned long, pointers...), Do you think that the only way is to convert each member?
Carrow
这篇关于如何将结构名称转换为字符串,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文