473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

syntax problem

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\MyProjects\Valid\Zenith124\Zenith.cpp(162) : error C2664:
'strlen' : cannot convert parameter 1 from 'char [12][104]' to 'const
char *'

can anyone help please.
Jul 19 '05 #1
4 3693

"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
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\MyProjects\Valid\Zenith124\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 multidimensional 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
Jul 19 '05 #2
"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
I'am having problem with the following:

rec1len = strlen(temp1);

temp1 is a character array,
It's an array of arrays in fact.
multi dimensional array.
it has been initialised as char temp1[12][104];
int rec1len.
error for this message: C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(162) : error C2664:
'strlen' : cannot convert parameter 1 from 'char [12][104]' to 'const
char *'

can anyone help please.


What is it that you're intending with strlen(temp1)? It's not 100% clear to
me.

If you want string length, which string do you want the length of? You have
an array of strings so identify which one you want, for instance:

int rec1len = strlen(temp[0]);

for the first string, or:

int rec12len = strlen(temp[11]);

for the last string.

Jul 19 '05 #3
"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om
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\MyProjects\Valid\Zenith124\Zenith.cpp(162) : error C2664:
'strlen' : cannot convert parameter 1 from 'char [12][104]' to 'const
char *'

can anyone help please.


Not sure what you are trying to do. strlen is not meant to work with
multi-dimensional arrays. You can call

strlen(temp1[i])

to get the length of row i for any i = 0 to 11. But this will only work if
the row is nul terminated. strlen counts the number of characters before the
'\0' character is encountered.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 19 '05 #4

"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
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];
declared as char temp1[12][104];, there's no initialisation going on there.
int rec1len.
error for this message: C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(162) : error C2664:
'strlen' : cannot convert parameter 1 from 'char [12][104]' to 'const
char *'

can anyone help please.


What did you expect to happen? strlen is for strings, i.e. *one* dimensional
character arrays. If you explain what you are trying to do someone will be
able to help.

john
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
24
by: Andrew Koenig | last post by:
PEP 315 suggests that a statement such as do: x = foo() while x != 0: bar(x) be equivalent to while True:
35
by: Moosebumps | last post by:
Does anyone here find the list comprehension syntax awkward? I like it because it is an expression rather than a series of statements, but it is a little harder to maintain it seems. e.g. you...
23
by: C. Barnes | last post by:
I vote for def f(): (body of function) This is backwards compatible (Python <= 2.3 raise SyntaxError), and looks much nicer than @. The only problem is that you can't one-line a...
16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
20
by: W Karas | last post by:
Would the fear factor for concepts be slightly reduced if, instead of: concept C<typename T> { typename T::S; int T::mem(); int nonmem(); };
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.