
November 20th, 2012, 08:22 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 11
Time spent in forums: 3 h 38 m 12 sec
Reputation Power: 0
|
|
Help with a linked list
Hi guys
I'm writing a linked list to store a strand of DNA(just a string of Chars really). Having problems adding to end of the list while in a while loop getting char's from keyboard
I know I could read into an array and the transfer to a linked list be that in my eyes would defeat the purpose, so here's what ive got
Code:
NODE_TYPE * addToList(NODE_TYPE *head) {
int inchar , FrstPass = 1;
NODE_TYPE *temp , *lstNode;
system("cls");
temp = head;
lstNode = head;
printf("Please enter a string of dna!\n-->") ;
while((inchar=getchar())!= 10) {
if (head == NULL) { //
head = getNode() ;
head->Next = NULL ;
head->letter = inchar ;
lstNode=head;
} else {
if (FrstPass) {
while((lstNode = lstNode->Next)!=NULL);//find the last node!
FrstPass=0;
}
temp=getNode();
temp->letter = inchar;
temp->Next = NULL;
lstNode->Next = temp;
lstNode = temp;
}
}
printf("List has been updated!" );
fflush(stdin);
getchar();
return head ;
|