Note that there are some explanatory texts on larger screens.

plurals
  1. POallocate memory for pointer to array of structure
    primarykey
    data
    text
    <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include "queue.h" #include "stack.h" #define RECORDS_SIZE 100 #define NAME_SIZE 20 typedef struct Student { char nameStudent[NAME_SIZE]; int TimeIn; int TimeUpdate; }STUDENT; typedef struct TUTOR { char nameTutor[NAME_SIZE]; int TutorTIme; STUDENT *ptr; }TUTOR; QUEUE *queue1; STACK *stack1; void getData(STUDENT *studentArr[RECORDS_SIZE]); int main (void) { STUDENT *studentArr[RECORDS_SIZE]; FILE *fp = NULL; getData(studentArr); return 0; } void getData(STUDENT *studentArr[RECORDS_SIZE]) { FILE *fp; char fileName[NAME_SIZE]; char buffer[RECORDS_SIZE]; int count = 0; printf("Enter file name: "); gets(fileName); fp = fopen(fileName, "r"); if (fp == NULL) { printf("Error! The file does not exist!\n"); } fgets(buffer, RECORDS_SIZE, fp); *studentArr = (STUDENT*) malloc(buffer[0]*sizeof(STUDENT)); while (fgets(buffer, RECORDS_SIZE, fp) != NULL) { printf("%s", buffer[count]); *studentArr[count]-&gt;nameStudent = (char*) malloc(strlen(buffer)*sizeof(char)); studentArr[count]-&gt;TimeIn = (int) malloc(strlen(buffer)*sizeof(int)); sscanf(buffer,"%[,],%d", *studentArr[count]-&gt;nameStudent, &amp;studentArr[count]-&gt;TimeIn); printf("%s%d\n", studentArr[count]-&gt;nameStudent, &amp;studentArr[count]-&gt;TimeIn); count++; } return; } </code></pre> <p>there is a warning that said assignment makes integer from pointer without a cast [enabled by default]| on the line where I allocate memory for *studentArr[count]->nameStudent, why am I getting this warning?</p> <p>This is what my file look like</p> <pre><code>4 A,10 B,12 C,60 D,120 tutorY </code></pre> <p>I tried to read in the first line then use the number on the first line to allocate the pointer to array of structure and the continue reading and then allocate the rest of members of structure</p> <p>I think i did the while loop wrong, may be I'm not suppose to call fgets and then reuse it in while loop as it appears to have an error there. How do I fix this function?</p> <p>thank in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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