intializing an array of strings in C

Discussion in 'C' started by doubty, Jun 19, 2009.

  1. doubty

    doubty New Member

    Joined:
    Jun 18, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. Aesop

    Aesop New Member

    Joined:
    Jun 19, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Could you elaborate please?
     
  3. doubty

    doubty New Member

    Joined:
    Jun 18, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  4. Aesop

    Aesop New Member

    Joined:
    Jun 19, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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++;
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice