473,748 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Mar 21 '06 #1
55 7091
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"

Mar 21 '06 #2
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

Mar 21 '06 #3
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 *'

Mar 21 '06 #4
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?

Mar 21 '06 #5
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
Mar 21 '06 #6
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 pissed in your breakfast but dude lighten up

Mar 21 '06 #7


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

--
Er*********@sun .com

Mar 21 '06 #8
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 pissed 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.

Mar 21 '06 #9
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:Th***** ********@gmail. com>

Mar 21 '06 #10

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

Similar topics

7
3347
by: Paul Sheer | last post by:
I need to automatically search and replace all fixed size buffer strcpy's with strncpy's (or better yet, strlcpy's) as a security and stability audit. The code base is large and it is not feasable to manually perform these changes. I would like perhaps a C++ parser that can automatically detect use of a strcpy to a buffer of fixed size. For instance, struct x { char member;
9
7778
by: Ape Ricket | last post by:
Hi. During my program's set-up phase where it reads in the arguments it was invoked with, I programmed this: if (strcmp(argv,"-G") ==0) { geom_scaling = ON; if (i < argc-1) strcpy(geom_string,argv); }
9
12790
by: Pascal Damian | last post by:
I read somewhere that strcpy() is safer when dealing with malloc()-ed strings. Is that true? (Of course I know that both are unsafe). -- Pascal
81
7329
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
302
18557
by: Lee | last post by:
Hi Whenever I use the gets() function, the gnu c compiler gives a warning that it is dangerous to use gets(). Is this due to the possibility of array overflow? Is it correct that the program flow can be altered by giving some specific calculated inputs to gets()? How could anyone do so once the executable binary have been generated? I have heard many of the security problems and other bugs are due to array overflows.
3
14309
by: naren | last post by:
Iam not getting the correct pros and cons of the strcpy() and memcpy() some where i read for short strings strcpy is faster and for large strings memcpy is faster.. in strcpy() there is a single pass over the data...but in memcpy() there are 2 passes..one is for strlen() and another is for copying.. but how memcpy will be faster for large strings? Can anybody please clear my doubt
9
2653
by: jim | last post by:
i want to make a c file that i can 'scanf ' students scores of 2 classes and their names , and i want it to get the sum of the 2 scores and make them in order .at last 'printf' /*am sorry,my english is not very good ,so u may have some difficulties in understanding my meaning ,but u can see the follow c file . thank u !*/
38
2725
by: edu.mvk | last post by:
Hi I am using strcpy() in my code for copying a string to another string. i am using static char arrays. for the first time it is exected correctly but the second time the control reaches then the SEGMENTATION FAULT is occuring. Please tell me what are all the cases this problem may occur if we use strcpy().
77
8355
by: arnuld | last post by:
I have created my own implementation of strcpy library function. I would like to have comments for improvements: /* My version of "strcpy - a C Library Function */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
0
8995
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
8832
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,...
0
9561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9332
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
9254
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
6799
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
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
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
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.