473,803 Members | 3,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\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.
Jul 19 '05 #1
4 3719

"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
Jul 19 '05 #2
"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,
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\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.


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**********@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.


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**********@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];
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\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.


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
34274
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 capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
303
17797
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. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
24
2718
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
3000
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 could do: result = for element in list: if element == 'blah':
23
1939
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 decorated function. You can't do that with
16
2611
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 useful for list/generator comprehensions, for example being able to write something like: instead of the less elegant explicit loop version that has to check for the length of each sequence. What do you think ? George
29
2477
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" for when and how to use single quotes and double quotes in ASP? thanks! ---------------------- SQL = SQL & "WHERE '" & REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE("GenKTitles.
5
14630
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 a total mistery. I have a function inside an ASP page as a result of which I get the following error message: Microsoft VBScript compilation error '800a03ea'
19
2981
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 $ Last-Modified: $Date: 2003/09/22 04:51:49 $ Author: Nicolas Fleury <nidoizo at gmail.com> Status: Draft Type: Standards Track
20
2600
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
9700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10292
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7603
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.