C struct sample
malloc struct
typedef struct XmlNode
{
int subNodeSize;
int nodeIndex;
} ;
XmlNode *rootNode = (XmlNode*)malloc(sizeof(XmlNode));
from https://openhome.cc/Gossip/CGossip/StructABC.html
typedef struct XmlNode
{
int subNodeSize;
int nodeIndex;
} ;
memset(rootNode , 0, sizeof(rootNode ));
from https://openhome.cc/Gossip/CGossip/StructABC.html
#include <stdio.h>
#include <string.h>
struct Ball {
char color[10];
double radius;
};
int main(void) {
struct Ball ball1 = {"red", 5.0};
struct Ball ball2;
strcpy(ball2.color, "green");
ball2.radius = 10.0;
printf("ball1: %s,\t%.2f\n", ball1.color, ball1.radius);
printf("ball2: %s,\t%.2f\n", ball2.color, ball2.radius);
return 0;
}
留言
張貼留言