create C structs using a variable as filename-Collection of common programming errors
You probably want a linked list, rather than an array, if you will be changing its size often. Then, your code looks something like:
typedef struct node{
char name;
char sname;
int number;
struct node* next;
}foo;
And you would use functions like the following to add new nodes/fetch nodes:
foo head = NULL;
void addNode(foo newNode)
{
if(head == NULL)
head = newNode;
else
{
foo temp = head;
while(foo->next != NULL)
foo = foo->next;
foo->next = newNode
}
}
foo fetchNode(int index)
{
if(index < 0)
return NULL;
int n = 0
foo temp = head;
while(n < index && temp != NULL)
{
temp = temp->next;
n++;
}
return temp;
}
The way this works is that each node has the necessary data, plus a pointer to the next node, which is NULL if its the last node. Then, all you need is a pointer to the first one and you can fetch nodes by walking the next pointers. This also makes it trivial to delete a node that is partway down the list.