"muser" <ch**********@h otmail.com> wrote in message
news:f9******** *************** ***@posting.goo gle.com...
I'am having problem with the following:
rec1len = strlen(temp1);
temp1 is a character array, multi dimensional array.
it has been initialised as char temp1[12][104];
int rec1len.
error for this message: C:\Program Files\Microsoft Visual
Studio\MyProjec ts\Valid\Zenith 124\Zenith.cpp( 162) : error C2664:
'strlen' : cannot convert parameter 1 from 'char [12][104]' to 'const
char *'
can anyone help please.
That's not how strlen() works. strlen() works with char*s, not character
arrays.
If you had something like this:
char temp1[12];
It would work if you took the address of that:
rec1len = strlen(&temp1);
But because you have a multidimensiona l array, you cannot do that. What I'm
assuming you're doing is having 104 "strings" which are up to 12 characters
long (or 12 strings up to 104 characters long). Note I say string here
meaning the C style string, that is, a char*. Perfectly legal in C++ but a
little bit harder to work with. If you must keep it char[12][104] and just
wanted to add up all of the string lengths, here's what you'll want to do:
rec1len = 0;
for (int x = 0; x < 104; x++)
rec1len += strlen(&temp1[x]);
I'm pretty sure that's how it works. I may have the two indexes mixed up,
but you're only supposed to put one of them down. I think it's the second
one, and then take the address of the first. Anyone else there please feel
free to pipe in if I got it wrong.
BTW: In C++, we have an easier way of dealing with strings, the aptly named
string class. First off, you'll need to
#include <string>
using namespace std; // if you haven't already
string temp1[104]; // make 104 strings
And now to add up the lengths, you could
rec1len = 0;
for (int x = 0; x < 104; x++)
rec1len += temp1[x].length();
Code Not Compiled
--
MiniDisc_2k2