Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

this is the code

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct listNode
{
char *Data;
struct listNode *nextPtr;
struct listNode *prevPtr;
};
typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;

void insert (ListNodePtr *, char *);
void printList (ListNodePtr );

int main()
{
ListNodePtr startPtr = NULL;
char item[512];

printf (&quot;Enter the text line: \n&quot;);
fgets (item, sizeof(item), stdin );
insert (&startPtr, item);
printList (startPtr);

return 0;
}

void insert (ListNodePtr *listptr, char value[])
{
ListNodePtr newPtr, previousPtr, currentPtr;

newPtr = malloc (sizeof (ListNode) );

if ( newPtr != NULL)
{
newPtr->Data = value;
newPtr->nextPtr = NULL;

previousPtr = NULL;
currentPtr = *listptr;

while ( currentPtr != NULL && value != '.')
{
previousPtr = currentPtr;
currentPtr = currentPtr->nextPtr;
previousPtr = previousPtr->prevPtr;
}

if (previousPtr == NULL)
{
newPtr->nextPtr = *listptr;
*listptr = newPtr;
}

else
{
previousPtr->nextPtr = newPtr;
newPtr->nextPtr = currentPtr;
newPtr->prevPtr = previousPtr;
}
}

else
printf (&quot;No memory is available.&quot;);
}

void printList (ListNodePtr currentPtr)
{
printf (&quot;The list is : \n&quot;);
printf (&quot;%s\n&quot;, currentPtr->Data);
currentPtr = currentPtr->nextPtr;

while (currentPtr != NULL)
{
printf (&quot;%s\n&quot;, currentPtr->Data);
currentPtr = currentPtr->nextPtr;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top