Hello Guys,
I have implemented a linked list. And my output looks something like dis:
*************************************************
The elements in the list :
address is = 163196952 ADOC1100250100000119666
address is = 163196968 ADOC1100250100000119666
address is = 163196984 ADOC1100250100000119666
address is = 0 ADOC1100250100000119666
TOTAL NO OF ELEMENTS IN THE LIST ARE 4
**************************************************
from the contents of the node, I should pick 1000011 and store it in a seperate array or structure. How do i pick part of the data from the node?

The data I'm inserting into the linked list is coming from a client program. It is a char array.

////*THIS FUNCTION ADDS A NODE AT THE LAST OF LINKED LIST */////
		void insertion(char buff[1024])
		{
			new=(N*)malloc(sizeof(N));
			new->info=buff;
			printf("contents of buffer %s\n",buff);
			printf("value inserted is %s\n",new->info);
			new->link=NULL;
			if(front==NULL && rear == NULL)
			{
				front = new;
				rear = new;
			}
			else
			rear->link=new;
			rear=new;
		}

I'm not sure if it would retrieve a part of the data within the node..I'l try..

strstr can't be used.the data keeps changing. i should fetch the data based on the byte position. Say from 12th byte till 19th byte.

you want to extract part of a string from within a string. the fact that this string is in a linked list is irrelevant. ask yourself the same question, but generalized: "How do i pick part of the data from the string? "

example: strncpy(&origString[10], subString, 5); will get bytes 10-14 of the origString and put it into subString.

Edited 6 Years Ago by jephthah: n/a

Hello,
How will I use strncpy to read from my buffer at some specified position till the end of line?I used like below.But it isn't displaying properly.:(

strncpy(&payload,&buff[23], (sizeof(buff));

use "strcpy()" ... note the lack of n.

so rather than specififying the number of bytes, n, as with strncpy(), it will just take the entire string from the starting pointer.

strcpy(&payload,&buff[23])

remember a "string" is defined by the presence of a terminating NULL character; your char data 'buff' must have a NULL at the end. most string functions (like strcpy() and sprintf()) put a NULL character at the end so this would only be a problem if you handcraft a character array and forget to terminate it with a NULL.


.

Edited 6 Years Ago by jephthah: n/a

This article has been dead for over six months. Start a new discussion instead.