Results 1 to 17 of 17

Thread: array

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    array

    how would i return an array?

    [CODE]
    void EnumerateStrings(char* &strings[])
    [CODE]

    or how owuld i pass an array by ref. ?
    thanks
    Amon Ra
    The Power of Learning.

  2. #2

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    i meant return an array of strings
    Amon Ra
    The Power of Learning.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You want to have an array of C strings returned? Return a pointer to the first element.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    so how would my function look?
    Code:
       char* Enumerate(char* value)
    {....}
    how would i create an array of C strings though?

    Code:
    char *buf[]; <-- ??wrong rite?
    thanks for helping
    Amon Ra
    The Power of Learning.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    and array of C strings is char**
    the buffer is an array of char arrays, ex:
    char buf[10][10];
    would make an array of Cstrings with length 10.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    so what would my function look like?

    PHP Code:
    char* * Enumerateint &count
    what if i wanna pass the c-strings array by reference??

    PHP Code:
    void Enumerate(char* * keysint &count)
    {
             
    keys[1] = "boom";
             
    keys[2] = "hello";
             return 
    keys;

    ...

    would that be right??
    Amon Ra
    The Power of Learning.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Why would you like to pass the c string array by reference? If you pass a pointer, the data will be assigned on the array anyway.
    But you can't have a buffer if you're going to assign it those things, then you would need an array of string pointers.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    so like this:

    Code:
    char ** enumerate(char *key)
    {...}
    ??
    thanks
    this function will basically return all the keys found in a section of the INI..i need to return an array of strings containing each key...
    Amon Ra
    The Power of Learning.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    So do you want to use a buffer instead? How long keys do you expect? btw char** for the buffer
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    sorry i am very confused..=)
    anyways..yea, basically i wanted to have a void function that would take an array of strings by ref. fill it with the keys in the INI file, and then exit..and since it was passed by ref...the original shouild have changed
    Amon Ra
    The Power of Learning.

  11. #11

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok, here is the vb function

    PHP Code:
    Public Sub EnumerateCurrentSection(ByRef sKey() As StringByRef iCount As Long)
    Dim sSection As String
    Dim iPos 
    As Long
    Dim iNextPos 
    As Long
    Dim sCur 
    As String
        
        iCount 
    0
        Erase sKey
        sSection 
    INISection
        
    If (Len(sSection) > 0Then
            iPos 
    1
            iNextPos 
    InStr(iPossSectionChr$(0))
            Do While 
    iNextPos <> 0
                sCur 
    Mid$(sSectioniPos, (iNextPos iPos))
                If (
    sCur <> Chr$(0)) Then
                    iCount 
    iCount 1
                    ReDim Preserve sKey
    (1 To iCount) As String
                    sKey
    (iCount) = Mid$(sSectioniPos, (iNextPos iPos))
                    
    iPos iNextPos 1
                    iNextPos 
    InStr(iPossSectionChr$(0))
                
    End If
            
    Loop
        End 
    If
    End Sub 
    here is what i wanna try to end up with.=)
    Amon Ra
    The Power of Learning.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    It's hard to follow what the vb function is suppose to do, looks like you split a string containing nulls but i'm not sure.

    You would have to do a different approach in C++. You can have a buffer with nullchars if you either both the pointer and then length of it or pointer to the end as well. Then you can use strlen to go trough the the string from the inifile, and memcpy to copy over the strings into the buffer, of course you have to know how long the keys are or you would need to allocate dynamical strings which makes the whole thing more complicated.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    You can have a buffer with nullchars if you either both the pointer and then length of it or pointer to the end as well.
    what do you mean exactly? do you mind writing a couple lines of code to show me? thanks..i realy need to get this string thing..=)
    Amon Ra
    The Power of Learning.

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yes, here's the idea:

    char* first;
    char* last;

    say you assign first with inibuffer which length is say 100 chars.

    first=inibuffer;

    then you need to know the end of the string:

    last=first+100;

    simple eh?

    now you can iterate trough the buffer without worrying when you need to end.

    for(char* i=first;i<last;i=strchr(i,0))strcpy(i,buffer++);

    as soon as i hits the wall (last) you're done.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok, so let me try..the buffer would then be something like char buf[100], right?

    for(char* i=first;i<last;i=strchr(i,0))strcpy(i,buffer++);
    PHP Code:

    void Enumerate
    (char *keys)
    {
        
    char buf[100];
        
    char *section IniSection   <- other function i wrote
        
        char 
    *first buf;
        
    char *last first buf;

        
    buf keys;

        for(
    char *i=firsti<lasti=strchr(i0))  {
              
    strcpy(ibuf++);

    so teh buffer is only for size? i ahve a function to retrieve the section, to look for keys..how do i go through the file though, and store the keys?
    the last line with buf++ increments the memory pos right?
    man, i dont know if iam ever gonna get this..lol
    Amon Ra
    The Power of Learning.

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yeah, it's called pointer aritmetics. change keys to char**
    and this line:
    strcpy(i, buf++);
    should be:
    strcpy(i, *buf++);
    it increments the array of the strings, not the char pos in the string.

    well i'll be back tomorrow.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  17. #17

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok great...thanks you very much...=)
    i'll try to figure it out and post it tmr..
    Amon Ra
    The Power of Learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width