I
irwa82
Hi,
I am new to C and created a list of structures linked together with
pointers. But I am wondering how you create a list if you don't have a
fixed number of entries. like if you had an address book you may not
know how many entries are there etc.
here is some sample code of my fix sized list:
#include <stdio.h>
#include <stddef.h>
int main(void) {
struct sTest {
int number;
struct sTest *next;
} s1, s2, s3, s4, s5, *sPointer;
sPointer = &s1;
s1.next = &s2;
s2.next = &s3;
s3.next = &s4;
s4.next = &s5;
s5.next = (struct sTest *) NULL;
s1.number = 15;
s2.number = 25;
s3.number = 35;
s4.number = 45;
s5.number = 55;
while (sPointer != (struct sTest *) NULL) {
printf("%i\n", sPointer->number);
sPointer = sPointer->next;
}
return 0;
}
I am new to C and created a list of structures linked together with
pointers. But I am wondering how you create a list if you don't have a
fixed number of entries. like if you had an address book you may not
know how many entries are there etc.
here is some sample code of my fix sized list:
#include <stdio.h>
#include <stddef.h>
int main(void) {
struct sTest {
int number;
struct sTest *next;
} s1, s2, s3, s4, s5, *sPointer;
sPointer = &s1;
s1.next = &s2;
s2.next = &s3;
s3.next = &s4;
s4.next = &s5;
s5.next = (struct sTest *) NULL;
s1.number = 15;
s2.number = 25;
s3.number = 35;
s4.number = 45;
s5.number = 55;
while (sPointer != (struct sTest *) NULL) {
printf("%i\n", sPointer->number);
sPointer = sPointer->next;
}
return 0;
}