Strcpy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jake Thompson

    #1

    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

    #2
    Re: Strcpy

    Jake Thompson opined:
    [color=blue]
    > I need to copy a value into a char * field.
    >
    > I am currently doing this
    >
    > strcpy(cm8link. type[count],"13");[/color]

    You don't give its declaration, but I bet the above is of type `char`
    rather than `char *`.
    [color=blue]
    > 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?[/color]

    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"

    Comment

    • Default User

      #3
      Re: Strcpy

      Jake Thompson wrote:
      [color=blue]
      > 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?[/color]

      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?
      [color=blue]
      > secondly how can i get the value into the field for this array
      > occurrence?[/color]

      What field? What array? Where's my damn crystal ball?

      You don't make easy for us to help you.



      Brian

      Comment

      • Jake Thompson

        #4
        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 *'

        Comment

        • santosh

          #5
          Re: Strcpy

          Jake Thompson wrote:[color=blue]
          > First of all I appreciate the help and certainly there is no need to
          > lash out[/color]

          Nobody is lashing out at you.
          [color=blue]
          > 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.[/color]

          But to see how and why you're using it the wrong way, we need to see
          the sorrounding relevent source, don't we?

          Comment

          • Default User

            #6
            Re: Strcpy

            Jake Thompson wrote:

            [color=blue]
            > 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.[/color]


            Then figure it out yourself.



            Brian

            Comment

            • Jake Thompson

              #7
              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 pissed in your breakfast but dude lighten up

              Comment

              • Eric Sosman

                #8
                Re: Strcpy



                Jake Thompson wrote On 03/21/06 16:04,:[color=blue]
                > 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[/color]

                ... 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?
                [color=blue]
                > 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.[/color]

                ... 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.)
                [color=blue]
                > 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 *'[/color]

                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

                Comment

                • santosh

                  #9
                  Re: Strcpy

                  Jake Thompson wrote:[color=blue]
                  > 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[/color]

                  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.

                  Comment

                  • Kenneth Brody

                    #10
                    Re: Strcpy

                    Jake Thompson wrote:[color=blue]
                    >
                    > 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[/color]

                    Obviously it's not, as the error says it's a "const char".
                    [color=blue]
                    > 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.[/color]

                    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.
                    [color=blue]
                    > In a nutshell I need to move a literal to a char * that is part of an
                    > array[/color]

                    An array of what?
                    [color=blue]
                    > 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],[/color]

                    But, what type is cm8link.type[2]? What is cm8link.type?
                    [color=blue]
                    > int count = 2;
                    >
                    > strcpy(cm8link. type[count],"13");
                    >
                    > resulting in the error
                    >
                    > error C2664: 'strcpy' : cannot convert parameter 1 from 'const char' to
                    > 'char *'[/color]

                    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:ThisIsA SpamTrap@gmail. com>

                    Comment

                    • Rod Pemberton

                      #11
                      Re: Strcpy


                      "Jake Thompson" <readytoride39@ hotmail.com> wrote in message
                      news:1142976521 .887321.172610@ v46g2000cwv.goo glegroups.com.. .[color=blue]
                      > 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[/color]

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


                      Rod Pemberton


                      Comment

                      • Jake Thompson

                        #12
                        Re: Strcpy

                        Sorry for my outburst


                        This is the function that I am calling



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


                        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
                        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*)par t->getPidObject() )->getItemId()
                        ; //Get the itemid

                        Is this enough information to go off of?

                        Comment

                        • Richard Tobin

                          #13
                          Re: Strcpy

                          In article <1142975062.133 232.313260@j33g 2000cwa.googleg roups.com>,
                          Jake Thompson <readytoride39@ hotmail.com> wrote:
                          [color=blue]
                          >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.[/color]

                          Since you have this problem, it's clear that there's something
                          about the program that you don't understand. So we can't (and you
                          shouldn't) trust your judgement as to what is "obvious".

                          In particular, we can't trust your claim that cm8link.type[count]
                          is of type char *. Show us the whole program!

                          -- Richard

                          Comment

                          • Keith Thompson

                            #14
                            Re: Strcpy

                            "Jake Thompson" <readytoride39@ hotmail.com> writes:[color=blue]
                            > 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[/color]

                            You need to provide context when you post a followup. Read
                            <http://cfaj.freeshell. org/google/>, and you'll understand how and
                            why.

                            Upthread, you 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.

                            If you already knew what the problem is, then presumably you wouldn't
                            need to ask for our help.

                            Conversely, the fact that you *are* asking for our help implies that
                            you really don't know what the problem is. If we offer you advice on
                            what information *we* need to help you solve *your* problem, then you
                            really should pay attention. We're not making you jump through hoops
                            just for the fun of it; we're asking you to help us to help you. If
                            you're unwilling to do so, then we can't help you.

                            --
                            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                            We must do something. This is something. Therefore, we must do this.

                            Comment

                            • Default User

                              #15
                              Re: Strcpy

                              Jake Thompson wrote:
                              [color=blue]
                              > 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.[/color]

                              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*



                              Brian

                              Comment

                              Working...