My node:
struct record
{
char name[25];
char address[80];
int yearofbirth;
char telno[15];
struct record* next;
};
add function:
int addRecord (struct record **start, char *name, char *address, int yOB, char *tel)
{
struct record *temp = NULL;
struct record *cursor = NULL;
temp = (struct record*) malloc(sizeof(struct record));
cursor = (struct record*) malloc(sizeof(struct record));
strcpy(temp->name, name);
strcpy(temp->address, address);
temp->yearofbirth = yOB;
strcpy(temp->telno, tel);
if(*start = NULL)
*start = temp;
else
cursor = *start;
while(cursor->next !=NULL)
{
cursor = cursor->next;
}
cursor->next = temp;
printf("\n%s\n", "Record added!");
free(cursor);
return 1;
}
and main:
int main(int argc, char* argv[])
{
struct record *start;
start = (struct record *) malloc(sizeof(struct record));
printf("%s\n", "Welcome to the phone book program");
addRecord(&start, "Name", "add", 123, "num");
return 0;
}
In order to make it easier to read, I cut out the majority of the code which I am pretty sure is working correctly (user interface/menu etc.)
Thank you for all feedback

New Topic/Question
Reply


MultiQuote




|