how would i return an array?
[CODE]
void EnumerateStrings(char* &strings[])
[CODE]
or how owuld i pass an array by ref. ?
thanks
Printable View
how would i return an array?
[CODE]
void EnumerateStrings(char* &strings[])
[CODE]
or how owuld i pass an array by ref. ?
thanks
i meant return an array of strings
You want to have an array of C strings returned? Return a pointer to the first element.
so how would my function look?
how would i create an array of C strings though?Code:char* Enumerate(char* value)
{....}
thanks for helpingCode:char *buf[]; <-- ??wrong rite?
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.
so what would my function look like?
what if i wanna pass the c-strings array by reference??PHP Code:char* * Enumerate( int &count)
would that be right??PHP Code:void Enumerate(char* * keys, int &count)
{
keys[1] = "boom";
keys[2] = "hello";
return keys;
...
}
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.
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...
So do you want to use a buffer instead? How long keys do you expect? btw char** for the buffer
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
ok, here is the vb function
here is what i wanna try to end up with.=)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
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.
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..=)Quote:
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.
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.
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++);
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?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++);
}
the last line with buf++ increments the memory pos right?
man, i dont know if iam ever gonna get this..lol
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.
ok great...thanks you very much...=)
i'll try to figure it out and post it tmr..