具有写功能的写数据结构

时间:2018-09-27 19:54:44

标签: c posix

我的笔记是写函数的第二个参数主要是一个字符串。我想知道是否可以将数据结构(例如:struct sockaddr_in)发送到第二个参数,以将其放入带有write的缓冲区中,然后在读取此缓冲区后使用它来获取起始元素。

如何在交换的内存和管道的上下文中使用?

示例:

    struct ess
{
    int valeur ;

    char indice ;

    char* description ;
};

int main(int argc, char const *argv[])
{
    struct ess *exemple ;

    exemple = (struct ess*)malloc((size_t)sizeof(struct ess)) ;

    exemple->val = 125 ;

    exemple->indice = 'o' ;

    exemple->description = "valeur adéquate" ;

    //Ecriture dans un tampon

    char *buffer ;

    buffer = (char*)malloc((size_t)sizeof(*exemple)) ;

    memmove(buffer , &(*exemple) , (size_t)sizeof(exemple)) ;

    struct ess *esi ;

    esi = (struct ess*)malloc((size_t)sizeof(struct ess)) ;

    memmove(&(*esi) , buffer , (size_t)sizeof(*esi)) ;

    printf("%s\n",esi->description );

    return 0;
}

存在细分错误

0 个答案:

没有答案
相关问题