Strcpy

J

Jake Thompson

This is the entire function from the module

long u_dll_cm8_getfolditemmatch(char *folderid, cm8linkstruc cm8link)
{
long l_stat = 0;
short dataid;
DKFolder* dkFOL = new DKFolder();
DKParts* dkParts = new DKParts();
DKLobICM* part = new DKLobICM();
DKString list;
int numD = 0;
int numF = 0;
DKString snumD;
DKString snumF;
DKString spnumber;
int count;
short itemPropertyType;
int h;


/*Create an ddoobject based upon the passed folder id */
DKDDO* ddoObject = dsICM->createDDO(folderid);

/*Get the contents of the folder */

dkFOL = (DKFolder*)(dkCollection*)
ddoObject->getData(ddoObject->dataId(DK_CM_NAMESPACE_ATTR,DK_CM_DKFOLDER));


dataid = ddoObject->dataId(DK_CM_NAMESPACE_ATTR,DK_CM_DKFOLDER);
if(dataid==0)
{
return 1; //No items in the folder
}

dkIterator* iter = dkParts->createIterator();
count = 0;
while(iter->more()) // while there are still items, continue
searching
{
part = (DKLobICM*) iter->next()->value(); // Move pointer
to next element & get the first note found.

itemPropertyType =
part->getPropertyByName(DK_CM_PROPERTY_ITEM_TYPE);

switch(itemPropertyType)
{
case DK_CM_DOCUMENT:

numD++;
snumD = DKString(numD); //Convert number to a string
strcpy(cm8link.type[count],"13"); //Copy the number 13 to indicate
folder
strcpy(cm8link.desc[count],"Document "); //copy the description
strcpy(cm8link.desc[count],snumD); //copy the current doc counter
to the description
strcpy(cm8link.item_increment[count],snumD); //copy Document
counter
cm8link.itemid[count] =
((DKPidICM*)part->getPidObject())->getItemId() ; //Get the itemid
break;

case DK_CM_FOLDER:
numF++;
snumF = DKString(numF);//Convert number to a string
strcpy(cm8link.type[count],"14"); //copy the number 14 to indicate
folder
strcpy(cm8link.desc[count],"Folder "); //copy the description
strcpy(cm8link.desc[count],snumF); //copy the current folder
counter to the description
strcpy(cm8link.item_increment[count],snumF); //copy Folder counter
cm8link.itemid[count] =
((DKPidICM*)part->getPidObject())->getItemId(); //Get the part number
break;

default:
break;
}
count++; //Increment the counter
}
delete(iter); // Free Memory
return 0;
}

This is the structure

struct cm8linkstruc
{
char* type; /* type of item*/
char* desc; /* description of item */
char* item_increment; /*increment value for item
in folder */
char* itemid; /* id of returned item */
};

As far as including the earlier text I do not know how to do that. I
am hitting reply so if I am not doing it right I apologize
 
L

lawrence.jones

Jake Thompson said:
First of all I appreciate the help and certainly there is no need to
lash out

Apparently, there is. When we provide advice and you ignore it,
additional emphasis is appropriate.
Secondly I did say that the field cm8link.type[count] is a char * field

Yes, you did; but it's not. If it were, you wouldn't be getting the
error you are. You have almost certainly declared it incorrectly, but
we can't tell for sure since you steadfastly refuse to show us the
actual declaration.
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.

There are lots of things that can cause an error. If you don't know
*what* the error is, then you have no way of knowing *where* the error
is, no matter how "obvious" you might think it. Thus, it is absolutely
necessary to provide a small but complete program that generates the
error. Please delete the parts of your program that aren't related to
the error, but make sure that the end result still compiles with the
same error.

-Larry Jones

It's like SOMEthing... I just can't think of it. -- Calvin
 
D

Default User

Keith said:
Default User said:
As you can't be bothered to follow simple instructions when you're
the one wanting help, plus you refuse to quote any context, it's
pretty obvious what happens next.


plonk

Then you probably missed his followup, in which he wrote:

] Sorry for my outburst

FWIW.

Checking Google, that seems to have been in response to Kenneth. If
he'd like to specifically apologize for what he said to me, then I'd
certainly be ready to write it off as one of those things that happens
some times in a written forum. Doubtlessly someone will keep me
apprised should that transpire.



Brian
 
M

Mark McIntyre

First of all I appreciate the help and certainly there is no need to
lash out

Nobody lashed out. But if you are asked to do something out of
courtesy, and then ignore that request, expect rude responses.
Also, please read this:

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

Show us the definition. The error can't arise if that definition is as
you assert.
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.

*sigh* You don't see the bug either. Do you see the connection?
 
M

Mark McIntyre

Well if it means dealing with a Dick as the alternative then hell yeah
I will figure it out myself.

You officially made it into the "arrogant newby who's too proud to
help himself" category. Well done.


Mark McIntyre
 
M

Mark McIntyre

struct cm8linkstruc
{
char* type; /* type of item*/

type is of type char*.
strcpy(cm8link.type[count],"13"); //Copy the number 13 to indicate

Therefore type[count] is of type char.

Also, you need to allocate memory for type before you can copy
something into it.

Mark McIntyre
 
K

Keith Thompson

Jake Thompson said:
This is the entire function from the module

But it's still not a complete program, which drastically limits how
much help we can offer.
long u_dll_cm8_getfolditemmatch(char *folderid, cm8linkstruc cm8link)
{
long l_stat = 0;
short dataid;
DKFolder* dkFOL = new DKFolder();
DKParts* dkParts = new DKParts();
[...]

According to groups.google.com, there have been 26 articles posted in
this thread. Until now, you've somehow managed to avoid posting
enough of your code to indicate that you're programming in C++, not C,
and therefore you're in the wrong newsgroup. (C and C++ are two
different languages; C has no "new" operator, among other
differences.)

If you really want help from comp.lang.c, post only C code. You may
be able to modify your code to be compatible with C (though so far you
haven't been able to show us code that's legal in any language).

Otherwise, the newsgroup you're looking for is comp.lang.c++.

Narrow down your program to a single, short, complete program, one
that doesn't depend on any external declarations or headers other than
those provided by the language standard. Show us something we can try
ourselves, and tell us what problem you're having with it. (In the
process of doing so, you might very well figure out the problem
yourself.)
As far as including the earlier text I do not know how to do that. I
am hitting reply so if I am not doing it right I apologize

We have been trying to tell you how to quote properly. Pay attention.

Read <http://cfaj.freeshell.org/google/>. Read it now. Read it
before you post another followup to this or any other newsgroup.
 
J

Jake Thompson

struct cm8linkstruc
{
char* type; /* type of item*/


type is of type char*.

strcpy(cm8link.type[count],"13"); //Copy the number 13 to indicate


Therefore type[count] is of type char.

Also, you need to allocate memory for type before you can copy
something into it.


Mark McIntyre

Mark,

If I am understanding you correctly type is a char * and type[count] is
a char. Is is correct? Why does adding an array value to data type of
char * turn it into type char? Is there a better way to get the move
the data? I know the idea came up to turn type into an int (and that
would work for the number) but I have another strcpy statement that
copies "Document " to another char * in the struture. I would really
like to understand so I can learn from this issue.

Thanks
Jake

Can
 
C

CBFalconer

Jake said:
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

Have fun. PLONK. I won't be seeing you.
 
C

CBFalconer

.... snip ...


There are lots of things that can cause an error. If you don't
know *what* the error is, then you have no way of knowing *where*
the error is, no matter how "obvious" you might think it. Thus,
it is absolutely necessary to provide a small but complete
program that generates the error. Please delete the parts of
your program that aren't related to the error, but make sure that
the end result still compiles with the same error.

Well, he has already been plonked for atrocious attitude by about
one-half of the people who could give him help. And that is just
those that announced it.
 
M

Mark McIntyre

If I am understanding you correctly type is a char * and type[count] is
a char. Is is correct?
Yes

Why does adding an array value to data type of
char * turn it into type char?

it doesn't 'turn it into' anything. It just is.

'type' is a pointer to a char.

so 'type[n]' is the n-th element of an array of chars starting at
address 'type'.

This is what the notation means.

I think you need to go back to a good C book and read the chapter on
pointers and arrays. Seriously.
Is there a better way to get the move
the data?

If you want to copy data, copy it to the right type of destination,
and make sure you allocate memory.

struct foo
{
char type[12]; // an array of 12 chars
char name[36]; // ditto but 36 chars
}

struct foo bar;

strcpy (bar.type, "12");
strcpy(bar.name "Laurence Llewelyn-Bowen");
..
Mark McIntyre
 
H

hdante

Hello,

Since you are using C++, you shouldn't be using pointers. Pointers are
very difficult to use and they are the reason of many security exploits
(see for example, http://en.wikipedia.org/wiki/Buffer_overflow ).

For your code, it's incorrect. cm8link.type is a 'char *', but
cm8link.type[2] is a const char. You really should be using the C++
standard library for this:

struct cm8item {
std::string type;
std::string desc;
std::string item_increment;
std::string itemid;
};

Then, in the code,

std::vector <cm8item> cm8link;
std::cm8item tmp;
tmp.type = "14";
tmp.desc = "Folder ";
cm8link.push_back(tmp);

See the STL manual for more info:
http://www.sgi.com/tech/stl/

And, sure, comp.lang.c++ ;-)
 
K

Keith Thompson

hdante said:
Since you are using C++, you shouldn't be using pointers. Pointers are
very difficult to use and they are the reason of many security exploits
(see for example, http://en.wikipedia.org/wiki/Buffer_overflow ). [snip]
And, sure, comp.lang.c++ ;-)

Offering C++ advice in comp.lang.c is not a good idea. Many of us
don't know C++ well enough to tell whether your advice is correct.

If the original poster wants C++ advice, he knows where to get it.
If he chooses not to post to comp.lang.c++, that's no reason to
start discussing C++ here.

Also, please provide context when you post a followup. Read
<http://cfaj.freeshell.org/google/> to understand how and why.
 
H

hdante

The reason is simple. You don't need to scare the poster.

You are too bureaucratic. I'm outta here. See ya.
 
B

Ben Pfaff

hdante said:
You are too bureaucratic. I'm outta here. See ya.

Don't forget to fill out Form #CLC-493 "Application To
Unsubscribe From comp.lang.c" on your way out.
 
O

Old Wolf

Jake said:
If I am understanding you correctly type is a char * and type[count] is
a char. Is is correct? Why does adding an array value to data type of
char * turn it into type char?

In C, the square brackets are used to select a member of an
array (or select an item out of a bunch of items that a pointer
is pointing to the first one of).
This is pretty basic and I suggest that you buy an introductory C
text such as "The C Programming Language" 2nd Edition by
Kernighan & Ritchie which provides a good introduction to the
language. Here is an example:

int main(void)
{
char const *str = "abcde";
char ch = str[2];

printf("The 3rd character of %s is %c.\n", str, ch);
}

Note how ch is a char and it was selected from str by using
the square brackets notation.
Is there a better way to get the move the data?

Please explain in English what you think [] means.
Nobody else on this group (me included) has yet
figured out what you are trying to do. Can you perhaps
post what you are expecting the string to be after this
operation you are attempting, and what it was beforehand?
I know the idea came up to turn type into an int (and that
would work for the number)
Huh?

but I have another strcpy statement that copies "Document "
to another char * in the struture. I would really like to
understand so I can learn from this issue.

If you are using C++ then you should use C++ string objects.
Then you can avoid advanced topics such as pointers and
memory allocation, until you are a bit more familiar with
the language.
 
A

Artie Gold

Jake said:
struct cm8linkstruc
{
char* type; /* type of item*/ type is of type char*.
strcpy(cm8link.type[count],"13"); //Copy the number 13 to indicate
Therefore type[count] is of type char.

Also, you need to allocate memory for type before you can copy
something into it.


Mark McIntyre

Mark,

If I am understanding you correctly type is a char * and type[count] is
a char. Is is correct? Why does adding an array value to data type of
char * turn it into type char?

In C, the expression x is identical to the expression *(x + i).[note]

Let's look at what the expression `type[count]' evaluates to, i.e.

type[count] === *(type + count)

Since `type' is a pointer to char (char *), `type + count' is also a
pointer to char. Dereferencing a pointer to char gives you a char.

[snip]

HTH,
--ag
 
C

CBFalconer

Old said:
Jake Thompson wrote:
.... snip ...
Is there a better way to get the move the data?

Please explain in English what you think [] means.
Nobody else on this group (me included) has yet
figured out what you are trying to do. Can you perhaps
post what you are expecting the string to be after this
operation you are attempting, and what it was beforehand?

Before i plonked him for bad attitude, his code appeared to be a
tortuous and error riddled attempt to write a decimal string to
numeric converter. Something like strtoul, but pretty foul. Just
ignore him.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
R

Robin Haigh

Jake Thompson said:
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]

if cm8link.type was a char*, then cm8link.type[count] is a char. So you
need to pass its address, not its value: &cm8link.type[count] or just
cm8link.type + count.

However, since the message says const char, you seem to be trying to write
into something that you've declared as read-only?
 
N

Nick Keighley

Default said:
As you can't be bothered to follow simple instructions when you're the
one wanting help, plus you refuse to quote any context, it's pretty
obvious what happens next.


*plonk*

hopefully Jake Thompson isn't hoping to make a career in programming
The ability to follow instructions (eg. RTFM) is invaluable
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top