C2664 can not convert from char[4] to char[]

I have a array and a function which take a char array as a parameter

char chs[4];

void func(char [] para)
{
    comecode;
}

func(chs);

when i try to call func, I got a compile error C2664 can not convert
from char[4] to char[],
how should i do this function call?

OS: Windows xp
Compiler:MS VC8

Thanks.

0
sevenever (5)
10/26/2007 8:11:36 AM
vc.mfc 33608 articles. 0 followers. Follow

9 Replies
684 Views

Similar Articles

[PageSpeed] 32

On Oct 26, 4:11 pm, sevenever <sevene...@gmail.com> wrote:
> I have a array and a function which take a char array as a parameter
>
> char chs[4];
>
> void func(char [] para)
> {
>     comecode;
>
> }
>
> func(chs);
>
> when i try to call func, I got a compile error C2664 can not convert
> from char[4] to char[],
> how should i do this function call?
>
> OS: Windows xp
> Compiler:MS VC8
>
> Thanks.

sorry, I send the wrong code.


const CString chs[4];

void func(CString para [] )
{


}
void function()
{
	func(chs);
}

0
sevenever (5)
10/26/2007 8:27:20 AM
"sevenever" <sevenever@gmail.com> ha scritto nel messaggio 
news:1193386296.312321.306660@t8g2000prg.googlegroups.com...
>I have a array and a function which take a char array as a parameter
>
> char chs[4];
>
> void func(char [] para)
> {
>    comecode;
> }
>
> func(chs);

Try this:

 void func( char * para )
 {
     some code ...
 }

 func( chs )


Giovanni


0
10/26/2007 8:27:53 AM
"sevenever" <sevenever@gmail.com> ha scritto nel messaggio 
news:1193387240.107589.82620@k35g2000prh.googlegroups.com...

> sorry, I send the wrong code.
>
>
> const CString chs[4];
>
> void func(CString para [] )
> {
>
>
> }

> func(chs);

Well, if you are using C++, then use robust classes, e.g. not a C-like 
unsafe fragile array, but a C++ container class, like CArray or 
std::vector...

e.g.

<code>
  typedef std::vector< CString > StringList;

  StringList strings( 4 );
  strings[0] = ... ;
  strings[1] = ... ;

  void Func( StringList & theStrings )
  {
        ...
  }

  Func( strings );

</code>

If your string list parameter is read-only, then you can use "const", like 
so:

  void Func( const StringList & theStrings )

Giovanni


0
10/26/2007 8:32:17 AM
On Oct 26, 4:11 pm, sevenever <sevene...@gmail.com> wrote:
> I have a array and a function which take a char array as a parameter
>
> char chs[4];
>
> void func(char [] para)
> {
>     comecode;
>
> }
>
> func(chs);
>
> when i try to call func, I got a compile error C2664 can not convert
> from char[4] to char[],
> how should i do this function call?
>
> OS: Windows xp
> Compiler:MS VC8
>
> Thanks.

sorry the code should be :


const char chs[4];

void func(char [] para)
{
    somecode;
}

func(chs);

0
sevenever (5)
10/26/2007 8:32:25 AM
On Oct 26, 4:27 pm, "Giovanni Dicanio" <giovanni.dica...@invalid.it>
wrote:
> "sevenever" <sevene...@gmail.com> ha scritto nel messaggionews:1193386296.312321.306660@t8g2000prg.googlegroups.com...
>
> >I have a array and a function which take a char array as a parameter
>
> > char chs[4];
>
> > void func(char [] para)
> > {
> >    comecode;
> > }
>
> > func(chs);
>
> Try this:
>
>  void func( char * para )
>  {
>      some code ...
>  }
>
>  func( chs )
>
> Giovanni

this function and the const chs[4] is not modifable, I can only modify
the caller code.

void func(char [] para)
 {
    comecode;
 }

Thanks.


0
sevenever (5)
10/26/2007 8:45:27 AM
sevenever wrote:
> const char chs[4];
> 
> void func(char [] para)
> {
>     somecode;
> }
> 
> func(chs);

If "chs" is const shouldn't "para" be const as well?
0
10/26/2007 9:27:51 AM
On Oct 26, 5:27 pm, Mihajlo Cvetanovic
<mcvetano...@gmail.nospampls.com> wrote:
> sevenever wrote:
> > const char chs[4];
>
> > void func(char [] para)
> > {
> >     somecode;
> > }
>
> > func(chs);
>
> If "chs" is const shouldn't "para" be const as well?

Yes, "para" should be const as well, the  void func(char [] para) dont
modify the array.

But if I cant fix this function as some reason, how can call it with a
const array?
declare a new array and copy content from the chs, call the function
with the new array as parameter?

0
sevenever (5)
10/26/2007 9:42:28 AM
sevenever wrote:
> sorry the code should be :
> 
> 
> const char chs[4];
> 
> void func(char [] para)
> {
>     somecode;
> }
> 
> func(chs);

sevenever:

Apart from const issues, it should be

void func(char para[])
{
     somecode;
}

not

void func(char [] para)
{
     somecode;
}

The first is equivalent to

void func(char* para)
{
     somecode;
}

-- 
David Wilkinson
Visual C++ MVP
0
no-reply8010 (1790)
10/26/2007 12:23:14 PM
Also, why is an obsolete data type like char being used in a modern program?

So are we talking about a char example or the CString example you later gave?

If it is a CString, you should not be declaring types like 
	CString chs[4];
because this doesn't make sense from a program robustness view point; C-style arrays
should be thought of as largely obsolete except in some very rare situations.  You should
be using CStringArray.
				joe

On Fri, 26 Oct 2007 09:42:28 -0000, sevenever <sevenever@gmail.com> wrote:

>On Oct 26, 5:27 pm, Mihajlo Cvetanovic
><mcvetano...@gmail.nospampls.com> wrote:
>> sevenever wrote:
>> > const char chs[4];
>>
>> > void func(char [] para)
>> > {
>> >     somecode;
>> > }
>>
>> > func(chs);
>>
>> If "chs" is const shouldn't "para" be const as well?
>
>Yes, "para" should be const as well, the  void func(char [] para) dont
>modify the array.
>
>But if I cant fix this function as some reason, how can call it with a
>const array?
>declare a new array and copy content from the chs, call the function
>with the new array as parameter?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
10/26/2007 12:41:22 PM
Reply:

Similar Artilces:

Can it be done??????????
Hi folks, I spent a lot of time on my chart but I couldn't figure out the solution. Is it possible to be done? Please show me how to do it? It is an urgent and very important to me. The following is my data: M1 ...

where can i get a template for a registraton form?
they weren't any that I saw available online. Take whatever form that is close and edit it to suit. Only you know for what folks are registering and what information is needed. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "L. Matthews" <L. Matthews@discussions.microsoft.com> wrote in message news:DA735DD5-27EC-49D3-BB83-EC30EAD8B87E@microsoft.com... > they weren't any that I saw available online. ...

This Idenity can not be opened with this version of Entourage message
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Email Client: pop I had to re-install MS office and now this is the meassage I receive from Entourage at open, What do I do? Make sure you apply all the updates by clicking on Help>Check for Updates. Your Entourage database was modified by a more recent version of Entourage and cannot be read by an earlier version. On 05/01/10 16:49, EmilyE@officeformac.com wrote: > Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Email > Client: pop I had to re-install MS office and now this is the meassage I &g...

Can this be done... ?
I have a routine form that I have to fill in which is basically a photocopy of an original which has long since gone. A lot of different people use this form so its not feasible for me to redo it and expect others to use the new one. My idea is to import this into a spreadsheet as a picture but to overlay it with input that is typed in and then printed off or faxed straight from the spreadsheet. I can't seem to make the picture go behind the cells so that the input from the cells is shown on top of the form. Does anyone have any ideas on how I could do this ? Thanks TW --- Message ...

How to Find non-primary smtp addresses so can remove
How to use the Find in AD to located mailboxes with a specific smtp (not primary) address so can remove them from the mailboxes. I can do the Find, but will only show users that have the specific smtp as the primary. Tks, Jim the proxyaddress attribute is a multi string value so you will either have to access in one of the following: ADUC - Create a custom LDAP search query and play around with the proxyaddress search criteria. Apologies but the vpn is down so cannot get into ADUC from here to be more exact OR via script using the GetEX property or via the various DS.. tools Or use WP...

in C# fastest way to convert a string into a MemoryStream
in C# fastest way to convert a string into a MemoryStream new MemoryStream(Encoding.UTF8.GetBytes(yourString)); But if the string is very large you may want to call Encoding.UTF8.GetEncoder() then encoding the string in buffer chunks and write those chunks to the memory stream. "Daniel" <softwareengineer98037@yahoo.com> wrote in message news:%23r4B$S7lFHA.3584@TK2MSFTNGP10.phx.gbl... > in C# fastest way to convert a string into a MemoryStream > > ...

error C2664.
Hi, i have an error in my application(vs2005). First i list .h and .cpp files and then i provide error description. If anybody know the solution please help me out. *************modifymediapage.h************** #include <vector> class Cmodifymediapage { ....; private: vector<CString> & m_vFieldVals; }; ****************modifymediapage.cpp**************** //this gives index of combo box selection int iPageSelect = m_PageNumber.GetCurSel(); if(m_vFieldVals.size()>=(iPageSelect+1)) { m_vFieldVals.erase(&m_vFieldVals[iPageSelect]);//error pointing here...

Can I get Sales Receipt after printing packing list?
when I get order from the customers, I print packing list from Work Order screen. Then, using this packing list, warehouse persons pick items for customers. I use packing list because it can be customized for a special field like bin location. After items are ready to pick up by customers, I open work order for sales. Unfortunately in this case, sales receipt doesn't print. It still prints workorder only. Any advice would be appreciated. -- Shalom! This is a multi-part message in MIME format. ------=_NextPart_000_0181_01C96118.95297000 Content-Type: text/plain; charset="utf-...

ASP.Net 4 TreeView Collapses on Node Click
I have an ASP.Net 4 TreeView that's being populated by a SQLSiteMapProvider and sits on a MasterPage. When I click a node the tree collapses. EnableViewState is set to True ViewStateMode is set to Enabled Am I missing something? How do I keep the tree state as it is when I click a link? "Dave" <Dave.Burkett@Jacobs.com> wrote in message news:2038c0ba-5328-4138-b615-777e02975478@c7g2000vbc.googlegroups.com... > Am I missing something? How do I keep the tree state as it is when I > click a link? This "feature" has always been there and I...

How can I make online paystubs?
...

Can I combine points in a scatter diagram without drawing by hand
I have made a line diagram with several series. The problem is that the different series don't have the same X values (it's different sampling dates), and when an X value is skipped for a serie (ex. dates 3/12, 5/12 och 9/12, where I only have Y values for the first and last date), the line diagram won't draw a line between my 2 Y values (that correspont to to the X values 3/12 and 9/12). I have a lot of data to work with, and now I draw lines between all points by hand. And that takes a LOT of time. Is there a better way??? Best regs, /Anna ...

CStringArray
Hello, I am trying to pass a CStringArray into a Class Function : Example: if(!WriteToFile.WriteInstalledApplications(CurrentApps.m_aPrograms)) bool WriteInstalledApplications(CStringArray mInstalledApps) { ofstream output("report.html",ios::app); output << "<br>"; However when I try to compile I get the following error: cannot convert parameter 1 from 'class CStringArray' to 'class CStringArray' Can someone give me an idea Thanks MarkS wrote: > Hello, > > I am trying to pass a CStringArray into a Class Function : > Exam...

in dotnet ide can you return to previous position
if you for instance select go to definition on some item in code, is there a way to return to the place you just were? like in vb6 view|last position thanks mark mp wrote: > if you for instance select go to definition on some item in code, is there a > way to return to the place you just were? > like in vb6 view|last position > thanks > mark > > The ctrl-key/minus key combination starts going back to the line positions and classes you were working with previously. Am 11.06.2010 03:06, schrieb mp: > if you for instance select go to definiti...

Can a blacklisted address be reversed?
I accidentally blacklisted an email address. Can this be reversed? If so, how? On Sun, 25 Apr 2010 17:08:01 -0700, citicountrychick <citicountrychick@discussions.microsoft.com> wrote: >I accidentally blacklisted an email address. Can this be reversed? If so, how? What version of Outlook? How did you 'blacklist' the address? -- To reply via e-mail, remove The Obvious and .invalid from my e-mail address. ...

How can I find duplicate entries in an entire worksheet?
I have pulled in information from a database and I am trying to remove duplicate records without having to look manually. Is there a way to do this? Take a look at http://cpearson.com/excel/duplicat.htm In article <BB25CF5A-3389-4C83-A0D6-05A6711BFF99@microsoft.com>, jbrown <jbrown@discussions.microsoft.com> wrote: > I have pulled in information from a database and I am trying to remove > duplicate records without having to look manually. Is there a way to do this? ASAP Utilities has a feature that does this nicely........... Free at www.asap-utilities.com Vay...

I can't get any reports
Hi, I'm using Money 2002. I can't seem to get any reports e.g. How much I spent on gas last month. I select the account, define the time frame, select the expense category but I get a completely blank report. Any idea what may be causing this? Thanks, Sam In microsoft.public.money, Sam wrote: >Hi, > >I'm using Money 2002. I can't seem to get any reports e.g. How much I spent >on gas last month. I select the account, define the time frame, select the >expense category but I get a completely blank report. > >Any idea what may be causing this? > I ...

why can't I open my Excel data in Excel, but I can as a merge sour
I need to add new fields to a data source that I am using for mail merge, but when I try to open it in Excel, I get an error message saying it is not a recognised file type. Help! What is the name of the file? How are you trying to open it? -- Jim Rech Excel MVP "legalsec" <legalsec@discussions.microsoft.com> wrote in message news:5C6F0709-5D43-4BE2-9EDF-4E9342BD05AC@microsoft.com... |I need to add new fields to a data source that I am using for mail merge, but | when I try to open it in Excel, I get an error message saying it is not a | recognised file type. Help! ...

publisher calendar #4
I'm making a school year calendar with Publisher 2003 -- how do I highlight and shade or fill individual days or weeks? Right-click the cell, format table, color... More than one day, click the cell, move the cursor until it high-lights the cell, continue until all the cells you need are selected. Help is your best friend... -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "braznell" <braznell@discussions.microsoft.com> wrote in message news:043C2438-CB0C-4DCD-BE21-EBDAC4DC5274@microsoft.com... > I'm makin...

can't email Yahoo & AOL
When I try to send mail to Yahoo or AOL I get a message saying “The following recipient(s) could not be reached: …Could not deliver the message in the time limit specified. Please retry or contact your administrator. <asumail.alasu.edu #4.4.7>” In the Exchange 2003 Queue I have 115 messages waiting to go out to Yahoo. What can I do to fix this? In news:214A4203-AA37-4E91-9250-829367258D41@microsoft.com, adrick <adrick@discussions.microsoft.com> typed: > When I try to send mail to Yahoo or AOL I get a message saying > "The following recipient(s) co...

Can receive but cannot send
I read through the entire string. I find lots of discussion, but few responses back from what actually worked, so ... here I go, adding to the choir. Just got a new Dell XPS M140, running McAffee v7 with firewall and spamkiller (not sure how much of this information is relevant, but more info is better, right?). I’m trying to run Outlook 2003, which came installed on the system. I can receive email but I cannot send. This is the message I get: The specified server was found, but there was no response from the server. Please verify that the port and SSL information is correct. ...

Can't access invoice designer
Recently when trying to access invoice designer in Money 2004 Small Business I get "Unexpected Error" window and an "OK" button to acknowlege it. Reinstalled money and service pack. Still not working. Now what? Did you remove or just reinstall? I would suggest removing and then reinstall to a different folder as a start. "Oh oh!" <anonymous@discussions.microsoft.com> wrote in message news:9c0301c478c8$e989a1c0$a501280a@phx.gbl... > Recently when trying to access invoice designer in Money > 2004 Small Business I get "Unexpected Error"...

How can Contacts from Lotus Notes be imported to Outlook?
I have used the comma separated values format to import Contacts into Outlook from other applications, but Lotus Notes does not offer this option. Any idea how to do this? Thanks! Marilyn Check this page for information on importing from other programs: http://www.slipstick.com/config/olimport.htm -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP http://home.hawaii.rr.com/schorr **I apologize but I am unable to respond to direct requests for assistance. Please post questions and replies here in the newsgroup. Mahalo! "Marilyn" <anonymous@discussions.microsoft.com> wrote in ...

How can I automatically put downloaded mail in a folder based on .
I would like to direct all mail from my hotmail account into a singl folder when using outlook 2007 Any Ideas -- Rick W You can use the Outlook Connector for that or configure Hotmail via POP3; http://www.msoutlook.info/question/332 If you are going for POP3, you set your delivery folder for the Hotmail account in your Account Settings. For details see; http://www.howto-outlook.com/howto/sortmail.htm -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.ms...

outlook express can't recv. e-mail
I get an error message. 0x800cccof. I.P. tells me to go to M.S. . M.S. tells me to go to I.P.. I have a place for both of them!!! Weeks and weeks of this. Microsoft thinks they fixed the problem. WRONG. Now M.S. wants to charge me for their problem software. I didn't write it. I paid for it once, I don't want to pay for it again. Please help, someone fix this, PLEASE, P.W. While your post makes almost no sense, i can tell you have a question about Outlook Express. This is a group to support Outlook from the Office group of programs. Outlook Express is a part of Internet ...

CRM 4 Outlook Client
Hi, Although it runs sometimes the majority of the time the CRM client is causing Outlook to hang. It either prevents outlook from opening, prevents messages from being dispayed or Outlook freezes when try and send a message. As soon as the CRM client is removed all is okay. Is anyone using it for real?! What might be making it so unrelieable for us? Marcus -- MR ICT Ltd - http://www.mrict.co.uk a) Delete (disabling is not sufficient!!!) every Anti Virus software on this computer. b) Disable all further addins inside Outlook. Does it work now? If not, open a service request with M...