Urgent please help LPSTR Array function passing problem 
Author Message
 Urgent please help LPSTR Array function passing problem

Hi Everyone,
            I have a problem which may be simple to some of you but its
giving me a headache.

I have a function :
/* ExternalFunctions.cpp */
#include "ExternalFunctions.h"

void FillArray(LPSTR  Ar[][3], CRecordset * set)
{
        int rec, Rows,Cols, c;
        CString  string;

        Rows = set->GetRecordCount();
        Cols = (short)set->GetODBCFieldCount();
        if(set->Open())
        {
                for (rec=0; rec < Rows ;rec++)
                {
                        for (c=0; c< Cols ;c++)
                        {
                                set->GetFieldValue((short)c,string);
                                strcat(Ar[rec][c],string.GetBuffer(80));
                                string.ReleaseBuffer();
                        }
                        set->MoveNext();
                }
        }
        set->Close();
        delete set;

Quote:
}

This fills an LPSTR array from a CRecordset.

The array has global scope i.e.

/* Ledger.h */
#include "ExternalFunctions.h";
extern LPSTR DDArray[][3];

/* Ledger.cpp */
LPSTR DDArray[][3];

This compiles with an error C2059 syntax error : ']'

on the function calling line in Ledger.cpp

FillArray(DDArray[][3], new CSetDistrictdivision(DB));
if I use:

FillArray(DDArray, new CSetDistrictdivision(DB));
I get another error LNK2001 unresolved external symbol "char * (*

How do I make this work do I change the calling function or is there
something wrong in the FillArray function.

Please help if you can this is delaying my development.

Thanks in advance.
Steven Henthorn
--
TxDOT

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Mon, 21 Jan 2002 03:00:00 GMT  
 Urgent please help LPSTR Array function passing problem
Quote:

>/* Ledger.cpp */
>LPSTR DDArray[][3];

>This compiles with an error C2059 syntax error : ']'

You have to specify a value in the [] when you are declaring the variable
itself.  So try something like
LPSTR DDArray[100][3];

Quote:
>on the function calling line in Ledger.cpp

>FillArray(DDArray[][3], new CSetDistrictdivision(DB));
>if I use:

>FillArray(DDArray, new CSetDistrictdivision(DB));
>I get another error LNK2001 unresolved external symbol "char * (*


I'm assuming, because of the compile error above, that DDArray was never
succesfully created,  Therefore, when you tried to use it, you get the link
error.  Correct the first item and I believe this will go away.

--------------------------------------------------------
http://www.openroad.org
A free website for beginner and student programmers.

"In computer programming, and motorcycle racing,
 Crashing sucks"
-Me



Mon, 21 Jan 2002 03:00:00 GMT  
 Urgent please help LPSTR Array function passing problem
First of all, how about using a CStringArray instead of the LPSTR Ar[][3].
As far as I can tell Ar is never given a actual size or initialized. Unless
you haven't included all of the source. Even if you get this to compile, I
see other problems that will keep you from getting the desired results.

i.e.

/* ExternalFunctions.cpp */
#include "ExternalFunctions.h"

void FillArray(CStringArray& stringarray, CRecordset * set)
{
 int rec, Rows,Cols, c;
 CString  string;

 Rows = set->GetRecordCount(); //  you are tying to get the record count
before the recordset is open!
                                                         // And even then
you must loop through the recordset with MoveNext until the end of the
recrodset is
                                                        //  reached before
the GetRecordCount will be correct.

 Cols = (short)set->GetODBCFieldCount();
 if(set->Open())
 {
 for (rec=0; rec < Rows ;rec++)
 {
 for (c=0; c< Cols ;c++)
 {
 set->GetFieldValue((short)c,string);
// instead of:
 strcat(Ar[rec][c],string.GetBuffer(80));
 string.ReleaseBuffer();
// use:
stringarray.add(string);

 }
set->MoveNext();

Quote:
}
}

set->Close();
delete set;

Quote:
}

Then call it with :
FillArray(GlobalStringArray, new CSetDistrictdivision(DB));

HTH

Matt



Mon, 21 Jan 2002 03:00:00 GMT  
 Urgent please help LPSTR Array function passing problem
I tried changing all references to the array from [][3] to [200][3].
This gives error:
C2664 'FillArray' : cannot convert parameter 1 from 'char *' to
char*[][3]'
on the same line where the function is called.
has anyone any suggestions?

thanks for the advice.
regards
Steven Henthorn



Quote:

> >/* Ledger.cpp */
> >LPSTR DDArray[][3];

> >This compiles with an error C2059 syntax error : ']'
> You have to specify a value in the [] when you are declaring the
variable
> itself.  So try something like
> LPSTR DDArray[100][3];

> >on the function calling line in Ledger.cpp

> >FillArray(DDArray[][3], new CSetDistrictdivision(DB));
> >if I use:

> >FillArray(DDArray, new CSetDistrictdivision(DB));
> >I get another error LNK2001 unresolved external symbol "char * (*

> I'm assuming, because of the compile error above, that DDArray was
never
> succesfully created,  Therefore, when you tried to use it, you get the
link
> error.  Correct the first item and I believe this will go away.

> --------------------------------------------------------
> http://www.openroad.org
> A free website for beginner and student programmers.

> "In computer programming, and motorcycle racing,
>  Crashing sucks"
> -Me

--
TxDOT

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Mon, 21 Jan 2002 03:00:00 GMT  
 Urgent please help LPSTR Array function passing problem
I have tried CStringArray and also CList but I can't seem to get an
error free build for a globaly (extern) defined multidimentional array.
I have problems defining it or in calling the function.

I thought using the LPSTR array would be quicker to implement.
Regards
Steve Henthorn



Quote:
> First of all, how about using a CStringArray instead of the LPSTR
Ar[][3].
> As far as I can tell Ar is never given a actual size or initialized.
Unless
> you haven't included all of the source. Even if you get this to
compile, I
> see other problems that will keep you from getting the desired
results.

> i.e.

> /* ExternalFunctions.cpp */
> #include "ExternalFunctions.h"

> void FillArray(CStringArray& stringarray, CRecordset * set)
> {
>  int rec, Rows,Cols, c;
>  CString  string;

>  Rows = set->GetRecordCount(); //  you are tying to get the record
count
> before the recordset is open!
>                                                          // And even
then
> you must loop through the recordset with MoveNext until the end of the
> recrodset is
>                                                         //  reached
before
> the GetRecordCount will be correct.

>  Cols = (short)set->GetODBCFieldCount();
>  if(set->Open())
>  {
>  for (rec=0; rec < Rows ;rec++)
>  {
>  for (c=0; c< Cols ;c++)
>  {
>  set->GetFieldValue((short)c,string);
> // instead of:
>  strcat(Ar[rec][c],string.GetBuffer(80));
>  string.ReleaseBuffer();
> // use:
> stringarray.add(string);

>  }
> set->MoveNext();
> }
> }
> set->Close();
> delete set;
> }

> Then call it with :
> FillArray(GlobalStringArray, new CSetDistrictdivision(DB));

> HTH

> Matt

--
TxDOT

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Tue, 22 Jan 2002 03:00:00 GMT  
 Urgent please help LPSTR Array function passing problem
What you are trying to do will not work:

1. LPSTR DDArray[100][3]  creates an array that will hold 300 char pointers
which as far as I can tell you haven't initialized yet.

2. strcat(Ar[rec][c],string.GetBuffer(80)); you are trying to concatinate
something onto nothing. (Ar[rec][c] doesn't contain a pointer (or a valid
one)).

add this before the strcat call:
Ar[rec][c] = new char[string.GetLength()];

but then you must remember to delete all of those char pointers before the
program exits.

Quote:

>I tried changing all references to the array from [][3] to [200][3].
>This gives error:
>C2664 'FillArray' : cannot convert parameter 1 from 'char *' to
>char*[][3]'
>on the same line where the function is called.
>has anyone any suggestions?

>thanks for the advice.
>regards
>Steven Henthorn



>> >/* Ledger.cpp */
>> >LPSTR DDArray[][3];

>> >This compiles with an error C2059 syntax error : ']'
>> You have to specify a value in the [] when you are declaring the
>variable
>> itself.  So try something like
>> LPSTR DDArray[100][3];

>> >on the function calling line in Ledger.cpp

>> >FillArray(DDArray[][3], new CSetDistrictdivision(DB));
>> >if I use:

>> >FillArray(DDArray, new CSetDistrictdivision(DB));
>> >I get another error LNK2001 unresolved external symbol "char * (*

>> I'm assuming, because of the compile error above, that DDArray was
>never
>> succesfully created,  Therefore, when you tried to use it, you get the
>link
>> error.  Correct the first item and I believe this will go away.

>> --------------------------------------------------------
>> http://www.openroad.org
>> A free website for beginner and student programmers.

>> "In computer programming, and motorcycle racing,
>>  Crashing sucks"
>> -Me

>--
>TxDOT

>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.



Tue, 22 Jan 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. please help with passing array to function

2. Passing an array into a function- Please Help!!

3. Help in passing the path to a C function - URGENT

4. Problem with passing array template array<int> as parameter in dll-function...please help

5. URGENT URGENT PLEASE HELP ME ActiveX multiples classes

6. Problems passing arrays of Strings to function.

7. Anwser: Problems passing a dynamic array of structures to a function

8. Problems passing a dynamic array of structures to a function

9. Please help me with passing struct Returning from function - pointer to

10. Help on passing array of structures to a function

11. Please help me solve this problem....urgent

12. Please help:Problem with interoperability-Urgent

 

 
Powered by phpBB® Forum Software