|
-
Oct 8th, 2001, 12:44 PM
#1
Thread Starter
Hyperactive Member
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.
-
Oct 8th, 2001, 12:46 PM
#2
Thread Starter
Hyperactive Member
i meant return an array of strings
Amon Ra
The Power of Learning.
-
Oct 8th, 2001, 01:19 PM
#3
transcendental analytic
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.
-
Oct 8th, 2001, 02:29 PM
#4
Thread Starter
Hyperactive Member
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.
-
Oct 8th, 2001, 03:02 PM
#5
transcendental analytic
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.
-
Oct 8th, 2001, 03:13 PM
#6
Thread Starter
Hyperactive Member
so what would my function look like?
PHP Code:
char* * Enumerate( int &count)
what if i wanna pass the c-strings array by reference??
PHP Code:
void Enumerate(char* * keys, int &count)
{
keys[1] = "boom";
keys[2] = "hello";
return keys;
...
}
would that be right??
Amon Ra
The Power of Learning.
-
Oct 8th, 2001, 03:28 PM
#7
transcendental analytic
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.
-
Oct 8th, 2001, 03:35 PM
#8
Thread Starter
Hyperactive Member
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.
-
Oct 8th, 2001, 03:38 PM
#9
transcendental analytic
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.
-
Oct 8th, 2001, 03:41 PM
#10
Thread Starter
Hyperactive Member
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.
-
Oct 8th, 2001, 03:43 PM
#11
Thread Starter
Hyperactive Member
ok, here is the vb function
PHP Code:
Public Sub EnumerateCurrentSection(ByRef sKey() As String, ByRef 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) > 0) Then
iPos = 1
iNextPos = InStr(iPos, sSection, Chr$(0))
Do While iNextPos <> 0
sCur = Mid$(sSection, iPos, (iNextPos - iPos))
If (sCur <> Chr$(0)) Then
iCount = iCount + 1
ReDim Preserve sKey(1 To iCount) As String
sKey(iCount) = Mid$(sSection, iPos, (iNextPos - iPos))
iPos = iNextPos + 1
iNextPos = InStr(iPos, sSection, Chr$(0))
End If
Loop
End If
End Sub
here is what i wanna try to end up with.=)
Amon Ra
The Power of Learning.
-
Oct 8th, 2001, 03:55 PM
#12
transcendental analytic
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.
-
Oct 8th, 2001, 04:07 PM
#13
Thread Starter
Hyperactive Member
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.
-
Oct 8th, 2001, 04:21 PM
#14
transcendental analytic
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.
-
Oct 8th, 2001, 04:45 PM
#15
Thread Starter
Hyperactive Member
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=first; i<last; i=strchr(i, 0)) {
strcpy(i, buf++);
}
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.
-
Oct 8th, 2001, 04:52 PM
#16
transcendental analytic
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.
-
Oct 8th, 2001, 05:05 PM
#17
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|