Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to work with pointer to pointer to a struct?
    text
    copied!<p>I have a bit of a problem. I am barely starting out with C, (comming from a C# background) and I am having problem with double pointers.</p> <p>I have a structure as follows:</p> <pre><code>#ifndef __PROCESSINFO_H #define __PROCESSINFO_H struct ProcessInfo { int ProcesId; int Priority; int ExecutionTime; int EllapsedTime; char* ProcessName; }; struct ProcessInfo *ProcessInfo_Allocate(int processId, char *processName, int priority, int executionTime); void ProcessInfo_ToString(struct ProcessInfo *processInfo); void ProcessInfo_Dispose(struct ProcessInfo *processInfo); #endif </code></pre> <p><strong>Implementation:</strong></p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;ctype.h&gt; #include "processinfo.h" struct ProcessInfo *ProcessInfo_Allocate(int processId, char *processName, int priority, int executionTime) { struct ProcessInfo *processInfo; processInfo = (struct ProcessInfo *)malloc(sizeof(struct ProcessInfo)); processInfo-&gt;ProcessId = processId; processInfo-&gt;ProcessName = processName; processInfo-&gt;Priority = priority; processInfo-&gt;ExecutionTime = executionTime; processInfo-&gt;EllapsedTime = 0; return processInfo; } void ProcessInfo_ToString(struct ProcessInfo *processInfo) { printf(" %6i %6i %10i %10i, %25s", processInfo-&gt;ProcessId, processInfo-&gt;Priority, processInfo-&gt;ExecutionTime, processInfo-&gt;EllapsedTime, processInfo-&gt;ProcessName); } void ProcessInfo_Dispose(struct ProcessInfo *processInfo) { if(processInfo != NULL) { if(processInfo-&gt;ProcessName != NULL) { free(processInfo-&gt;ProcessName); } free(processInfo); } } </code></pre> <p>so now I have to manage a whole lot of ProcessInfo instances. I wrote another structure which would hold a pointer to a pointer to the ProcessInfo sturcture because i thought that I can increase and decrease it in size as needed (without too much hassle);</p> <pre><code>#ifndef __SCHEDULER_H #define __SCHEDULER_H struct Scheduler { struct ProcessInfo** Processes; }; struct Scheduler* Scheduler_Allocate(void); #endif </code></pre> <p>So the question is how do I initialize the **Processes member inside the <code>Scheduler_Allocate</code> method? How do I add stuff to it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload