其主要依靠函数指针来实现,具体看代码吧~

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct string
{
    char data[128];
    int length;
    void (*set)(struct string *it, int len);
} String;
void set(String *it, int len)
{
    it->length = len;
    memset(it->data, 0, 128);
}

int main()
{
    String S1;
    S1.set = set;
    S1.set(&S1, 0);
    return 0;
}

相关文章:

  • 2021-07-23
  • 2022-12-23
  • 2021-09-02
  • 2021-10-28
  • 2021-06-17
  • 2022-01-21
  • 2021-10-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
相关资源
相似解决方案