Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 嵌套结构问题_C_Structure - Fatal编程技术网

C 嵌套结构问题

C 嵌套结构问题,c,structure,C,Structure,如何在结构中创建节点数组。 我上传了我的样本 struct timebasedSpecificTimesIntervalNode { int hrs; int min; int sec; }; struct timebasedSpecificTimesInterval { struct timebasedSpecificTimesIntervalNode* nodes; int count; char *cFilePath; };

如何在结构中创建节点数组。 我上传了我的样本

 struct timebasedSpecificTimesIntervalNode
 {
   int hrs;
   int min;
   int sec;
 };

 struct timebasedSpecificTimesInterval
 {
     struct timebasedSpecificTimesIntervalNode* nodes;
     int count;
     char *cFilePath;
 };
如何为此结构创建基于时间的SpecificTimesInterval的节点数组

  struct timebasedSpecificTimesInterval specificTimes;
如何为此结构创建包含3个节点的数组

编辑

为该值创建结构

  hrs:5,2,3 min 23,58,4 sec 54,12,2

除非我误解了这个问题。。。与任何其他阵列一样:

struct timebasedSpecificTimesInterval specificTimes[3];

编辑:使用OP中提供的示例这是我将如何做的。除非我完全弄错了方向。我不喜欢新的struct关键字乱扔我的代码

typedef struct 
 {
   int hrs;
   int min;
   int sec;
 } timebasedSpecificTimesIntervalNode;

 typedef struct 
 {
     timebasedSpecificTimesIntervalNode* nodes;
     int count;
     char *cFilePath;
 } timebasedSpecificTimesInterval;

int main (void)
{
  timebasedSpecificTimesIntervalNode nodeArray[3];  
  timebasedSpecificTimesInterval specificTimesInterval;

  //initialise the pointer
  specificTimesInterval.nodes = nodeArray;

  // you can now access the pointer as an array
  nodeArray[0].hrs = 3; //arbitrary value

}

struct timebasedSpecificTimesInterval specificTimes[3]??@OAOD:实际上,timebasedSpecificTimesInterval不应该是数组。只有timebasedSpecificTimesInterval中的节点才应该是数组。从您的问题中,仍然不清楚您到底想要实现什么。静态初始化,在运行时,正好是3,还是更多(或更少)?
struct timebasedSpecificTimesIntervalNode{int hrs[3].
每次你键入timebasedSpecificTimesInterval,上帝就会杀了一只小猫。@pmg:你能把这些小时、秒、分钟分配到这个结构中吗?这对我很有帮助。我看过你的编辑后就编辑了我的帖子。希望它现在对你有用…@pmg:非常感谢。这就是我想要的…+1作为你的答案
typedef struct 
 {
   int hrs;
   int min;
   int sec;
 } timebasedSpecificTimesIntervalNode;

 typedef struct 
 {
     timebasedSpecificTimesIntervalNode* nodes;
     int count;
     char *cFilePath;
 } timebasedSpecificTimesInterval;

int main (void)
{
  timebasedSpecificTimesIntervalNode nodeArray[3];  
  timebasedSpecificTimesInterval specificTimesInterval;

  //initialise the pointer
  specificTimesInterval.nodes = nodeArray;

  // you can now access the pointer as an array
  nodeArray[0].hrs = 3; //arbitrary value

}