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!

how to input 10 text lines in to the files?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi
how do i input 10 text lines from the terminal and store it into the doubly linked list. plz help me if u can
thanks
 
int i=10
char data[1024]={0};
struct textdata{
char *text;
struct textdata *next;
struct textdata *prev;
};
struct textdata *head;
int add_list(char *data, int len)
{
struct textdata *node=(struct textdata *)malloc(sizeof(struct textdata));
if(!node)
return -1;
memset(node, 0, sizeof(struct textdata));
node->text=(char *)malloc(len);
if(!node->text)
{
free(node);
return -1;
}
memcpy(node->text, data, len);
node->next=node;
node->prev=node;
if(!head)
head=node;
else
{
node->next=head->next;
node->prev=head;
head->next->prev=node;
head->next=node;
}
return 0;
}
void create_list()
{
for(;i!=0;i--)
{
int len=0;
gets(data);
len=strlen(data);
add_list(data, len);
}
}



Njoy dear...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top