Strcpy

N

Nick Keighley

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


when you are asked to post a short complete example that exhibts the
problem you should have posted something like this:-

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 */
};



long u_dll_cm8_getfolditemmatch (char *folderid, cm8linkstruc cm8link)
{
int count;

strcpy(cm8link.type[count],"13"); //Copy the number 13 to indicate
folder`
return 0;
}


see? easy. I suggest you learn to accept advice if you want people to
help you.
 
C

Chris Dollin

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

If you don't understand the problem, you don't understand what's
/relevant/ to the problem. You're asking us to guess what else
you've done. We might guess wrong. We might waste your time and
ours with our wrong guesses.

If you construct a complete, minimal example that shows the
problem, you might solve it for yourself in the process. Hooray!
Otherwise, we can see /exactly/ what code you used and get to
the heart of the problem immediately. Hooray!

Otherwise, we are treading in mud, wearing streaky glasses and
breathing acrid dust. No hooray. BOOM tomorrow.
error C2664: 'strcpy' : cannot convert parameter 1 from 'const char' to
'char *'

Well, that's a pretty straightforward diagnostic. Parameter 1 of
strcpy should be a char*, but you gave it a const char. Don't do
that.
 
K

Kenneth Brody

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

.... in triplicate. Keep the white form, send the yellow form to the
comp.lang.c owner, and the blue form gets submitted with your copy of
Form #CLC++001 "Application To Subscribe To comp.lang.c++". (The
green copy is no longer needed.)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

Kenneth Brody

(Quoting corrected.)

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?
Correct.

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

While, technically, a "char *" is a "pointer to char", it is typically
used as a "pointer to an array of chars".

Think of it this way:

char *welcome = "Hello, world\n";

"welcome" is a "char *", pointing to the string "Hello, world\n", but
"welcome[3]" is a "char" with a value of 'l'. For the same reason,
"cm8link.type" is a "char *", but "cm8link.type[count]" is a 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.

What, exactly, are you trying to do with the statement:

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

Is it possible that you really want:

strcpy(cm8link.type+count,"13");

which will store the three characters '1', '3', '\0' starting at the
given offset within the buffer?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
C

CBFalconer

Kenneth said:
... in triplicate. Keep the white form, send the yellow form to
the comp.lang.c owner, and the blue form gets submitted with your
copy of Form #CLC++001 "Application To Subscribe To comp.lang.c++".
(The green copy is no longer needed.)

Use a ball point pen and press heavily. You are making 4 copies.

--
"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/>
 
J

Jake Thompson

Kenneth said:
(Quoting corrected.)

Jake said:
On 21 Mar 2006 13:59:53 -0800, in comp.lang.c , "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?
Correct.

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

While, technically, a "char *" is a "pointer to char", it is typically
used as a "pointer to an array of chars".

Think of it this way:

char *welcome = "Hello, world\n";

"welcome" is a "char *", pointing to the string "Hello, world\n", but
"welcome[3]" is a "char" with a value of 'l'. For the same reason,
"cm8link.type" is a "char *", but "cm8link.type[count]" is a 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.

What, exactly, are you trying to do with the statement:

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

Is it possible that you really want:

strcpy(cm8link.type+count,"13");

which will store the three characters '1', '3', '\0' starting at the
given offset within the buffer?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>

Ulitmately what I want to do is build an array of values so that I can
take each occurence of count(my array incrementor) to use it to build a
what I call a link list in another function


What I do is allocate my array in one function and then pass it to my
secondary function so that I can loop through an index and when I get a
hit on a certain type I want to store it away as an occurence

for example say I i loop through 10 items in the secondary function and
two of those items match my criteria - at that point in time I want to
store 4 things in an array for that occurrence

Those four things are
type ,desc, item_increment, and itemid


Occurence 1

type = "13"
desc = "Document"
item_increment =Document1"
itemid p75554

Occurence 2

type = "13"
desc = "Document"
item_increment =Document2"
itemid p76666

When I return to the calling function I want to be able to loop through
the newly built array that has the two occurrences and build my link
list

I used char * for my field types because I wanted to use functions
strcpy and strcat in order to manipulate some of the data specifically
item_increment where I concatenate a number onto the desc field.

Jake
 
R

Rod Pemberton

Rod Pemberton said:
Unfortunately, his attitude is the majority here. Certain individuals will
call you off-topic or a troll despite the fact that they've only posted
complaints and have never posted anything C related:

Brian "Default User"
CBFalconer
Richard Bos
etc...

I forgot to add a few people to that list who just try to kill conversation.
You can see from their follow up posts I speak the truth:

Al "Em" Balmer
Keith "Kill It" Thompson
Mark "The Ass" McIntyre
CB "PLONK" Falconer

Some of these guys are just ridiculous. I think Falconer is going for the
world record in calling people troll's. He's used "PLONK" two hundred and
ninety-three times and still hasn't contributed anything topical or
non-topical.


Rod Pemberton
 
J

Jake Thompson

Jake said:
Kenneth said:
(Quoting corrected.)

Jake said:
On 21 Mar 2006 13:59:53 -0800, in comp.lang.c , "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?
Correct.

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

While, technically, a "char *" is a "pointer to char", it is typically
used as a "pointer to an array of chars".

Think of it this way:

char *welcome = "Hello, world\n";

"welcome" is a "char *", pointing to the string "Hello, world\n", but
"welcome[3]" is a "char" with a value of 'l'. For the same reason,
"cm8link.type" is a "char *", but "cm8link.type[count]" is a 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.

What, exactly, are you trying to do with the statement:

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

Is it possible that you really want:

strcpy(cm8link.type+count,"13");

which will store the three characters '1', '3', '\0' starting at the
given offset within the buffer?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>

Ulitmately what I want to do is build an array of values so that I can
take each occurence of count(my array incrementor) to use it to build a
what I call a link list in another function


What I do is allocate my array in one function and then pass it to my
secondary function so that I can loop through an index and when I get a
hit on a certain type I want to store it away as an occurence

for example say I i loop through 10 items in the secondary function and
two of those items match my criteria - at that point in time I want to
store 4 things in an array for that occurrence

Those four things are
type ,desc, item_increment, and itemid


Occurence 1

type = "13"
desc = "Document"
item_increment =Document1"
itemid p75554

Occurence 2

type = "13"
desc = "Document"
item_increment =Document2"
itemid p76666

When I return to the calling function I want to be able to loop through
the newly built array that has the two occurrences and build my link
list

I used char * for my field types because I wanted to use functions
strcpy and strcat in order to manipulate some of the data specifically
item_increment where I concatenate a number onto the desc field.

Jake

Well I figured it out - I had my subscript in the wrong location

I had cm8link.type[count] when I should of had cm8link[count].type

thanks to all that provided helpful replies
 
M

Michael Mair

Funny, you seem to miss their C posts that I see.
I forgot to add a few people to that list who just try to kill conversation.
You can see from their follow up posts I speak the truth:

Al "Em" Balmer
Keith "Kill It" Thompson
Mark "The Ass" McIntyre
CB "PLONK" Falconer

Some of these guys are just ridiculous. I think Falconer is going for the
world record in calling people troll's. He's used "PLONK" two hundred and
ninety-three times and still hasn't contributed anything topical or
non-topical.

Apart from Chuck's "open plonk" policy and the number of plonks
you counted (which I did not), this is plainly wrong.

I suggest that you review the average "quality" of _your_
contributions, as it suffers by your pointless diatribes.

-Michael
 
R

Rod Pemberton

Michael Mair said:
Funny, you seem to miss their C posts that I see.

I've seen two from CBFalconer today, after I posted this. The first in four
months.
Apart from Chuck's "open plonk" policy and the number of plonks
you counted (which I did not),

This isn't the only group he spams. That's his Google cached total.
this is plainly wrong.

I suggest that you review the average "quality" of _your_
contributions, as it suffers by your pointless diatribes.

Diatribes, perhaps. Pointless, no. They are an attempt to bring an
awareness of the fact that a small group is castigating hundreds, and
perhaps thousands of others over time, in this newsgroup. Castigation which
is uncalled for and unnecessary. If you were subscribed to any other
newsgroup, you'd know this to be true. If I must be the sacrificial pawn to
bring about this awareness, then so be it. It's truly unfortunate that you
choose to defend the strong at the expense of the weak. I doubt anyone
would call you noble.


Rod Pemberton
 
M

Michael Mair

<snip: List of clc regulars whic Rod deems overly harsh in their
dealings with others while not contributing anything C related>
I've seen two from CBFalconer today, after I posted this. The first in four
months.

You are kidding or have a strange news server.
There was at least one more within the last couple of days.
Look near my posts.
His posts certainly are not insightful articles bringing forth
delight in experienced and unexperienced readers alike but if
we held everyone to this standard, then Chris Torek would be
rather lonesome round here but they provided me with useful
information in the past and still do.
This isn't the only group he spams. That's his Google cached total.

If you say so.
Diatribes, perhaps. Pointless, no. They are an attempt to bring an
awareness of the fact that a small group is castigating hundreds, and
perhaps thousands of others over time, in this newsgroup. Castigation which
is uncalled for and unnecessary.

I am not sure about your choice of words; it sounds rather
preachy and exaggerated.
As I have seen enough disorganised newsgroups, mailing lists
and other go down, I prefer clear rules and adherence to them
within _sensible_ bounds. Your approach sounds more as if you
expect the best outcome from a thorough lack of rules and
organisation.

Whether the people you denounced as the evil castigators work
within said sensible bounds is open to debate; interestingly,
there are several more regular contributors who have similar
views as they have.

If you were subscribed to any other
newsgroup, you'd know this to be true.

Hmmm, I count more than one newsgroup that I write to regularly
and several more that I read regularly.
> If I must be the sacrificial pawn to
> bring about this awareness, then so be it.

You seem to enjoy broadcasting your martyrdom too much for my
taste.
> It's truly unfortunate that you choose to defend the strong at
> the expense of the weak. I doubt anyone would call you noble.

Nice judgement there.


-Michael
 
M

Mark McIntyre

Ulitmately what I want to do is build an array of values so that I can
take each occurence of count(my array incrementor) to use it to build a
what I call a link list in another function

okay, you want an array of the struct.:

struct foo {int x; char name[12];};

struct foo[12]; // an array of 12 structs

for(int i = 0;i<12;i++)
{
foo[n].x = 12;
strcpy(foo[n].name, "Jake");
}

Mark McIntyre
 
M

Mark McIntyre

Well I figured it out - I had my subscript in the wrong location

I had cm8link.type[count] when I should of had cm8link[count].type

make sure you also correct your memory allocation error - as declared,
cm8link.type doesn't point to any valid memory, so you can't strcpy
anything into it.
Mark McIntyre
 
C

CBFalconer

Michael said:
Rod Pemberton schrieb:
.... snip ...


Apart from Chuck's "open plonk" policy and the number of plonks
you counted (which I did not), this is plainly wrong.

I suggest that you review the average "quality" of _your_
contributions, as it suffers by your pointless diatribes.

Whee - I've made the record books. Double entry yet. However
there seems to be something imperfect about his sampling
technique. Looking in my current PLONK file for c.l.c I find 8
individual entries, and 5 threads. RP will be glad to know he is
the eldest, apart from Skybuck, who may have gone to troll heaven
and no longer require dealing with.

If only people would refrain from amusing trolls, things would
clean up much more quickly.

--
"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/>
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top