Re: Strcpy
On 21 Mar 2006 13:59:53 -0800, "Jake Thompson"
<readytoride39@ hotmail.com> wrote in comp.lang.c:
[color=blue]
> Sorry for my outburst[/color]
OK, but I'm still not sure that you're getting the point.
[color=blue]
> This is the function that I am calling[/color]
You aren't showing a function at all.
[color=blue]
> char *folderid;
> struct cm8linkstruc cm8link; <----------------structure tag set to
> cm8link
>
>
>
> struct cm8linkstruc
> {
> char* type; /* type of item*/
> <------------------------------------------field that I want to copy
> the "13" too
> char* desc; /* description of item */
> char* item_increment; /*increment value for item
> in folder */
> char* itemid; /* id of returned item */
> };[/color]
At last, a definition of the structure! This structure contains four
members (there is no such thing as a "field" defined by the C
language), and each of the fields is a pointer to char.
Up above you show the definition of an object of this type, named
"cm8link". Since you're still not posting the real code that your
compiler is seeing, there is information lacking.
Is "cm8link" defined at file scope (outside of all functions), or is
it defined at local scope (inside of a function)? It makes a
difference, should your code ever compile, because you are heading for
a run time problem.
If "cm8link" is defined at file scope, the four char pointers are
initialized to NULL. If it is defined in a local scope, the four char
pointers are not initialized at all. In either case, they do not
point to valid memory that you can read from or write to.
[color=blue]
> These are the lines of code that I am trying to execute in order to
> copy the values too.
>
> strcpy(cm8link. type[count],"13"); //Copy the number 13 to indicate
> folder[/color]
I know you resent being asked for enough information to understand
what mistakes you are making, BUT WHAT THE HELL IS "count"?!? WHERE
IS "count" DEFINED?!?
[color=blue]
> strcpy(cm8link. desc[count],"Document "); //copy the description
> strcpy(cm8link. desc[count],snumD); //copy the current doc counter to
> the description[/color]
WHAT THE HELL IS "snumD"?!?
[color=blue]
> strcpy(cm8link. item_increment[count],snumD); //copy Document counter
> cm8link.itemid[count] = ((DKPidICM*)par t->getPidObject() )->getItemId()
> ; //Get the itemid
>
> Is this enough information to go off of?[/color]
No, actually, it is not. If you have actually properly initialized
the character pointers to valid memory that you have the right to
write to, then cm8link.desc[count] is a SINGLE CHARACTER, and you
can't copy a string into a SINGLE CHARACTER. If you haven't
initialized the character pointers, they don't point anywhere and you
can't write to them at all.
Multiple people have tried to explain to you, most of them patiently,
but you aren't getting it.
POST THE ACTUAL CODE THAT YOU ARE COMPILING. OF THE WHOLE FUNCTION.
COPY IT FROM YOUR TEXT EDITOR AND PASTE IT INTO A MESSAGE. ALSO COPY
THE DECLATATION OF EACH DATA TYPE, AND THE DEFINITION OF EACH OBJECT
THAT IS MENTIONED IN THE CODE. PASTE IT ALL INTO YOUR MESSAGE.
There are several possible different mistakes that you might be
making, and nobody here is willing to put that much effort into
guessing, maybe correctly or maybe incorrectly.
STOP TRYING TO GUESS HOW LITTLE REAL INFORMATION PEOPLE NEED TO HELP
YOU. YOU'RE GUESSING WRONG. IF YOU AREN'T WILLING TO PROVIDE
EVERYTHING I ASKED FOR ABOVE, THEN YOU SHOULD GO AWAY AND FIGURE IT
OUT FOR YOURSELF.
Now I've got a sore throat from ALL THE SHOUTING.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
On 21 Mar 2006 13:59:53 -0800, "Jake Thompson"
<readytoride39@ hotmail.com> wrote in comp.lang.c:
[color=blue]
> Sorry for my outburst[/color]
OK, but I'm still not sure that you're getting the point.
[color=blue]
> This is the function that I am calling[/color]
You aren't showing a function at all.
[color=blue]
> char *folderid;
> struct cm8linkstruc cm8link; <----------------structure tag set to
> cm8link
>
>
>
> struct cm8linkstruc
> {
> char* type; /* type of item*/
> <------------------------------------------field that I want to copy
> the "13" too
> char* desc; /* description of item */
> char* item_increment; /*increment value for item
> in folder */
> char* itemid; /* id of returned item */
> };[/color]
At last, a definition of the structure! This structure contains four
members (there is no such thing as a "field" defined by the C
language), and each of the fields is a pointer to char.
Up above you show the definition of an object of this type, named
"cm8link". Since you're still not posting the real code that your
compiler is seeing, there is information lacking.
Is "cm8link" defined at file scope (outside of all functions), or is
it defined at local scope (inside of a function)? It makes a
difference, should your code ever compile, because you are heading for
a run time problem.
If "cm8link" is defined at file scope, the four char pointers are
initialized to NULL. If it is defined in a local scope, the four char
pointers are not initialized at all. In either case, they do not
point to valid memory that you can read from or write to.
[color=blue]
> These are the lines of code that I am trying to execute in order to
> copy the values too.
>
> strcpy(cm8link. type[count],"13"); //Copy the number 13 to indicate
> folder[/color]
I know you resent being asked for enough information to understand
what mistakes you are making, BUT WHAT THE HELL IS "count"?!? WHERE
IS "count" DEFINED?!?
[color=blue]
> strcpy(cm8link. desc[count],"Document "); //copy the description
> strcpy(cm8link. desc[count],snumD); //copy the current doc counter to
> the description[/color]
WHAT THE HELL IS "snumD"?!?
[color=blue]
> strcpy(cm8link. item_increment[count],snumD); //copy Document counter
> cm8link.itemid[count] = ((DKPidICM*)par t->getPidObject() )->getItemId()
> ; //Get the itemid
>
> Is this enough information to go off of?[/color]
No, actually, it is not. If you have actually properly initialized
the character pointers to valid memory that you have the right to
write to, then cm8link.desc[count] is a SINGLE CHARACTER, and you
can't copy a string into a SINGLE CHARACTER. If you haven't
initialized the character pointers, they don't point anywhere and you
can't write to them at all.
Multiple people have tried to explain to you, most of them patiently,
but you aren't getting it.
POST THE ACTUAL CODE THAT YOU ARE COMPILING. OF THE WHOLE FUNCTION.
COPY IT FROM YOUR TEXT EDITOR AND PASTE IT INTO A MESSAGE. ALSO COPY
THE DECLATATION OF EACH DATA TYPE, AND THE DEFINITION OF EACH OBJECT
THAT IS MENTIONED IN THE CODE. PASTE IT ALL INTO YOUR MESSAGE.
There are several possible different mistakes that you might be
making, and nobody here is willing to put that much effort into
guessing, maybe correctly or maybe incorrectly.
STOP TRYING TO GUESS HOW LITTLE REAL INFORMATION PEOPLE NEED TO HELP
YOU. YOU'RE GUESSING WRONG. IF YOU AREN'T WILLING TO PROVIDE
EVERYTHING I ASKED FOR ABOVE, THEN YOU SHOULD GO AWAY AND FIGURE IT
OUT FOR YOURSELF.
Now I've got a sore throat from ALL THE SHOUTING.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
Comment