Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   intializing an array of strings in C (http://www.go4expert.com/forums/intializing-array-strings-c-t18107/)

doubty 19Jun2009 15:11

intializing an array of strings in C
 
Hi I have a string , out of which iam trying to extract relevant substrings. the substrings are being stored in an array of strings, now my problem is that initially i need to push the initial string as one of the elements of the array of substrings ( the original string it self), i.e in my array of substrings, the first element should be the string it self.

Aesop 20Jun2009 04:30

Re: intializing an array of strings in C
 
Could you elaborate please?

doubty 21Jun2009 13:22

Re: intializing an array of strings in C
 
HI this is my query :

I have a string A(A(c))

I have extracted all the substrings of it i.e A(A(c)),A(c),c

I have writtena recursive function to extract the substrings, and i need to store the substrings into an array of strings, Iam having issues in doing so

lets say
if(openbrac_count==closebrac_count & openbrac_count != 0)
{
strncpy(label[j][50],inputexp,i);
j++;
}
i need to store the substring into the array of strings label, please help.

Aesop 22Jun2009 17:35

Re: intializing an array of strings in C
 
If beginning is the index of the first char of inputexp that you want in the substring, and if length is the length of the substring, then
Code:

strncpy(label[j],inputexp+beginning,length);
label[j][length] = 0;
j++;



All times are GMT +5.5. The time now is 09:15.