1. ## Array of structs

4
1 5
2 -4
-3 9
8 2

The first integer, call it n, is the number of
complex numbers to follow. The n complex numbers
are then listed. Your program must dynamically
allocate enough memory to store the array of n
complex numbers. Complex numbers must be stored
in a structure. (So you have an array of
structures.) Then your program should loop through
the array from end to front, and print out the
complex numbers in it. E.g., your output should
look like
8 + 2i
-3 + 9i
2 + -4i
1 + 5i
on stdout.

I have no idea how to allocate memory for something like this, if the stuff is inputted, how do u know how big the struct or array is to put the numbers in, can someone demonstrate the code for that part?

Thanks

2. just to mention, that the info is being read from a file

3. Code:
```struct test
{
int r, i;
};

/* Read n from the file */
struct test *t = malloc ( n * sizeof *t );
for ( i = 0; i < n; i++ ) {
/* Fill the array up to t[n - 1] */
}```
-Prelude

4. Code:
```#include <stdio.h>
#include <stdlib.h>

typedef struct
{
int x;
int y;
} COMPLEX_NUMBER;

int main (void)
{
int i, counter;
FILE *fp;
COMPLEX_NUMBER *pCN;

fp = fopen ("datafile", "r");

fscanf (fp, "%d", &counter);

pCN = malloc (counter * sizeof (COMPLEX_NUMBER));

for (i = 0; i < counter; i++)
fscanf (fp, "%d%d", &(pCN + i)->x, &(pCN + i)->y);

for (i = counter - 1; i >= 0; i--)
printf ("%5d%5d\n", (pCN + i)->x, (pCN + i)->y);

fclose (fp);

return 0;
}```

5. Originally posted by PutoAmo
Code:
```#include <stdio.h>
#include <stdlib.h>

typedef struct
{
int x;
int y;
} COMPLEX_NUMBER;

int main (void)
{
int i, counter;
FILE *fp;
COMPLEX_NUMBER *pCN;

fp = fopen ("datafile", "r");

fscanf (fp, "%d", &counter);

pCN = malloc (counter * sizeof (COMPLEX_NUMBER));

for (i = 0; i < counter; i++)
fscanf (fp, "%d%d", &(pCN + i)->x, &(pCN + i)->y);

for (i = counter - 1; i >= 0; i--)
printf ("%5d%5d\n", (pCN + i)->x, (pCN + i)->y);

fclose (fp);

return 0;
}```

I have never understood why the hell people do everyone's entire homework project for them... The only time I do this, the code is an "alternate" way of doing it, that either (a) they wouldn't understand, (b) their teacher wouldn't accept the code for a grade, (c) the teacher would know that there's no way in hell the student wrote this code...

Quzah.