/* how would I go about freeing the memory assigned in the loop
for the nodes*/
#include<string.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 30
struct node{
int age;
char name[MAX];
node *next;
};
int main()
{
int amount;
cout<<"How many people to be stored";
cin>>amount;
/* ptr is of type node its assigned the starting address of */
node *ptr=(node*)malloc(sizeof(node)); /* a block of memory the size of node */
/* malloc must be cast in c++ and not in c */
strcpy(ptr->name,"ANTHONY");
cout<<ptr->name;
for(int start=0;start<amount;start++)
{
ptr->next=(node*)malloc(sizeof(node));
ptr=ptr->next;
}
ptr=NULL;
getch();
return 0;
}
/* thanks for all the help */