Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Strcpy (http://www.velocityreviews.com/forums/t441909-strcpy.html)

Jake Thompson 03-21-2006 08:27 PM

Strcpy
 
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


Vladimir S. Oka 03-21-2006 08:44 PM

Re: Strcpy
 
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"


Default User 03-21-2006 08:46 PM

Re: Strcpy
 
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


Jake Thompson 03-21-2006 09:04 PM

Re: Strcpy
 
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 *'


santosh 03-21-2006 09:19 PM

Re: Strcpy
 
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?


Default User 03-21-2006 09:22 PM

Re: Strcpy
 
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

Eric Sosman 03-21-2006 09:26 PM

Re: Strcpy
 


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).

--
Eric.Sosman@sun.com


Jake Thompson 03-21-2006 09:28 PM

Re: Strcpy
 
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


santosh 03-21-2006 09:35 PM

Re: Strcpy
 
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.


Kenneth Brody 03-21-2006 09:45 PM

Re: Strcpy
 
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: <mailto:ThisIsASpamTrap@gmail.com>



All times are GMT. The time now is 08:59 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.