Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Strcpy

Reply
Thread Tools

Strcpy

 
 
Jake Thompson
Guest
Posts: n/a
 
      03-21-2006
I need to copy a value into a char * field.

I am currently doing this

strcpy(cm8link.type[count],"13");

but I get an error of

error C2664: 'strcpy' : cannot convert parameter 1 from 'const char' to
'char *'

this used to when it was just cm8link.type but it errors when I make it


cm8link.type[count]

first of all why?

secondly how can i get the value into the field for this array
occurrence?

Thanks

Jake

 
Reply With Quote
 
 
 
 
Vladimir S. Oka
Guest
Posts: n/a
 
      03-21-2006
Jake Thompson opined:

> I need to copy a value into a char * field.
>
> I am currently doing this
>
> strcpy(cm8link.type[count],"13");


You don't give its declaration, but I bet the above is of type `char`
rather than `char *`.

> but I get an error of
>
> error C2664: 'strcpy' : cannot convert parameter 1 from 'const char'
> to 'char *'
>
> this used to when it was just cm8link.type but it errors when I make
> it
>
>
> cm8link.type[count]
>
> first of all why?
>
> secondly how can i get the value into the field for this array
> occurrence?


Please post a small compilable example of your code that exhibits the
problem (and it's output).


--
BR, Vladimir

Americans' greatest fear is that America will turn out
to have been a phenomenon, not a civilization.
-- Shirley Hazzard, "Transit of Venus"

 
Reply With Quote
 
 
 
 
Default User
Guest
Posts: n/a
 
      03-21-2006
Jake Thompson wrote:

> I need to copy a value into a char * field.
>
> I am currently doing this
>
> strcpy(cm8link.type[count],"13");
>
> but I get an error of
>
> error C2664: 'strcpy' : cannot convert parameter 1 from 'const char'
> to 'char *'
>
> this used to when it was just cm8link.type but it errors when I make
> it
>
>
> cm8link.type[count]
>
> first of all why?


We went over this last time. Post a COMPLETE, minimal program that
compiles and demonstrates the problem.

How can we possibly say anything without seeing the declarations of the
variables?

> secondly how can i get the value into the field for this array
> occurrence?


What field? What array? Where's my damn crystal ball?

You don't make easy for us to help you.



Brian

 
Reply With Quote
 
Jake Thompson
Guest
Posts: n/a
 
      03-21-2006
First of all I appreciate the help and certainly there is no need to
lash out

Secondly I did say that the field cm8link.type[count] is a char * field

I don't see the need to have the entire program listed. It is a one
line statement that obviously I am using the wrong way.

In a nutshell I need to move a literal to a char * that is part of an
array

currently as an example I am doing the following just so you know count
is normally incremented in a loop but here i set it to clearly define
that I want to move the value 13 into

cm8link.type[2],

int count = 2;

strcpy(cm8link.type[count],"13");

resulting in the error

error C2664: 'strcpy' : cannot convert parameter 1 from 'const char' to

'char *'

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      03-21-2006
Jake Thompson wrote:
> First of all I appreciate the help and certainly there is no need to
> lash out


Nobody is lashing out at you.

> Secondly I did say that the field cm8link.type[count] is a char * field
>
> I don't see the need to have the entire program listed. It is a one
> line statement that obviously I am using the wrong way.


But to see how and why you're using it the wrong way, we need to see
the sorrounding relevent source, don't we?

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      03-21-2006
Jake Thompson wrote:


> I don't see the need to have the entire program listed. It is a one
> line statement that obviously I am using the wrong way.



Then figure it out yourself.



Brian
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      03-21-2006


Jake Thompson wrote On 03/21/06 16:04,:
> First of all I appreciate the help and certainly there is no need to
> lash out
>
> Secondly I did say that the field cm8link.type[count] is a char * field


... but since the compiler contradicted you (it
described the field as `const char'), didn't it occur
to you to offer the actual code so someone could try to
judge whether you or the compiler is in error?

> I don't see the need to have the entire program listed. It is a one
> line statement that obviously I am using the wrong way.


... and the "what's wrong with it" is clearly a
matter of context. Can you tell, without looking at
any of the rest of the program, whether the one line

x = 42;

is right or wrong? (If you think you can, you need to
re-open your C textbook.)

> In a nutshell I need to move a literal to a char * that is part of an
> array
>
> currently as an example I am doing the following just so you know count
> is normally incremented in a loop but here i set it to clearly define
> that I want to move the value 13 into
>
> cm8link.type[2],
>
> int count = 2;
>
> strcpy(cm8link.type[count],"13");
>
> resulting in the error
>
> error C2664: 'strcpy' : cannot convert parameter 1 from 'const char' to
>
> 'char *'


You claim that `cm8link.type[2]' is a `char*', while the
compiler claims it's a `const char'. Without further evidence
it would be injudicious to say which of you is right -- but
I'm forced to disclose, right here on my jury screening form,
that I am more likely to believe the compiler's testimony than
yours. Since I am obviously prejudiced, I won't be empanelled
(a lucky break for you; I'm in a mood to hang uncooperative
witnesses).

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Jake Thompson
Guest
Posts: n/a
 
      03-21-2006
Well if it means dealing with a Dick as the alternative then hell yeah
I will figure it out myself.

Thank God your attitude is the minority here.

I don't know who ****ed in your breakfast but dude lighten up

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      03-21-2006
Jake Thompson wrote:
> Well if it means dealing with a Dick as the alternative then hell yeah
> I will figure it out myself.
>
> Thank God your attitude is the minority here.
>
> I don't know who ****ed in your breakfast but dude lighten up


This is not a forum to throw mud at each other. Admittedly Default User
was rather curt in his reply, but the point he, I and several others
have made to you still stands, i.e. post the smallest compilable code
that exhibits your problem or failing that atleast post relevant
sarrounding code like data declarations, prototypes etc., so that we
don't have to keep guessing.

Also please quote the post to which you're replying. Most regulars in
this group, access it via nntp servers which might delete articles
after a certain time, unlike Google Groups. Including context makes the
post comprehendable in such cases.

 
Reply With Quote
 
Kenneth Brody
Guest
Posts: n/a
 
      03-21-2006
Jake Thompson wrote:
>
> First of all I appreciate the help and certainly there is no need to
> lash out
>
> Secondly I did say that the field cm8link.type[count] is a char * field


Obviously it's not, as the error says it's a "const char".

> I don't see the need to have the entire program listed. It is a one
> line statement that obviously I am using the wrong way.


The problem is that without seeing the actual definition of
cm8link.type[count], people can only guess as to the "real"
problem. The compiler says one thing, and you say something
else. We tend to believe the error message over your claim
until you show us the compiler is wrong.

> In a nutshell I need to move a literal to a char * that is part of an
> array


An array of what?

> currently as an example I am doing the following just so you know count
> is normally incremented in a loop but here i set it to clearly define
> that I want to move the value 13 into
>
> cm8link.type[2],


But, what type is cm8link.type[2]? What is cm8link.type?

> int count = 2;
>
> strcpy(cm8link.type[count],"13");
>
> resulting in the error
>
> error C2664: 'strcpy' : cannot convert parameter 1 from 'const char' to
> 'char *'


While tells us that cm8link.type[count] is of type "const char", and
not the "char *" that you continue to claim.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <(E-Mail Removed)>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strcpy of a class object leonkatz@gmail.com C++ 11 01-20-2005 04:44 AM
strcpy and the copy constructor RonHiler C++ 8 10-19-2004 06:30 AM
C++ Compiler with a -Wwarn-use-of-strcpy or similar option?? Paul Sheer C++ 4 09-14-2004 08:38 PM
C++ Compiler with a -Wwarn-use-of-strcpy or similar option?? Paul Sheer C++ 7 09-10-2004 05:07 PM
strcpy Mike Mimic C++ 9 05-17-2004 08:12 PM



Advertisments