2 dimensional strcpy err

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

    #1

    2 dimensional strcpy err

    char chain[10][300];


    strcpy(chain[i+20], chain[i]);


    error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
    Conversion from integral type to pointer type requires
    reinterpret_cas t, C-style cast or function-style cast


    how to amend that?


  • Guy

    #2
    Re: 2 dimensional strcpy err

    strcpy((char*)c hain + 300*(i+20) , (char*)chain + 300*i);


    ~ ªÑ²¼»ù®æ¦³¤É¦³¶ ^, ¶R½æ­n¯à©Ó¾á­·À I ~

    ~ Samba, more than a low cost File and Printer server ~

    -- Let us OpenSource --

    Comment

    • Jens.Toerring@physik.fu-berlin.de

      #3
      Re: 2 dimensional strcpy err

      Ross <kk-leung@cuhk.edu. hk> wrote:[color=blue]
      > char chain[10][300];[/color]
      [color=blue]
      > strcpy(chain[i+20], chain[i]);[/color]
      [color=blue]
      > error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
      > Conversion from integral type to pointer type requires
      > reinterpret_cas t, C-style cast or function-style cast[/color]
      [color=blue]
      > how to amend that?[/color]

      First thing I would try to do in your case would be to invoke your
      compiler in C and not C++ mode. Second, you should make sure that
      you don't use array elements that don't exist. With the above 'i'
      would have to be between -20 and -11 in order not to access an
      element outside of the 'chain' array for the first argument to
      strcpy(), but, on the other hand, 'i' has to be between 0 and 20
      for the second argument - which it obviously can't be both at the
      same time.
      Regards, Jens
      --
      \ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
      \______________ ____________ http://www.toerring.de

      Comment

      • Martin Ambuhl

        #4
        Re: 2 dimensional strcpy err

        Ross wrote:[color=blue]
        > char chain[10][300];[/color]
        [color=blue]
        > strcpy(chain[i+20], chain[i]);[/color]
        [color=blue]
        > error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
        > Conversion from integral type to pointer type requires
        > reinterpret_cas t, C-style cast or function-style cast[/color]
        [color=blue]
        > how to amend that?[/color]

        Use a C compiler. You are using a C++ compiler. If your product claims
        to compile both C and C++, then it has different ways of invoking it for
        the two different languages. Read the documentation.

        Comment

        • Keith Thompson

          #5
          Re: 2 dimensional strcpy err

          "Ross" <kk-leung@cuhk.edu. hk> writes:[color=blue]
          > char chain[10][300];
          >
          >
          > strcpy(chain[i+20], chain[i]);
          >
          >
          > error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
          > Conversion from integral type to pointer type requires
          > reinterpret_cas t, C-style cast or function-style cast[/color]

          As others have mentioned, you should invoke your compiler in C mode
          rather than C++ mode, but I don't think that's your problem.

          The first argument to strcpy is of type char[300], which is converted
          to char*. The compiler is saying that it's of type char. The only
          explanation I can think of is that the code you posted isn't the same
          as the code you're trying to compile.

          If you post a code sample, you need to cut-and-paste the *exact* code;
          we can't guess what your actual code looks like.

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

          • Jack Klein

            #6
            Re: 2 dimensional strcpy err

            On 26 Dec 2004 00:27:22 +0800, "Guy" <boring__guy@ho tmail.com> wrote
            in comp.lang.c:
            [color=blue]
            > strcpy((char*)c hain + 300*(i+20) , (char*)chain + 300*i);[/color]

            There are so many things wrong with this post that I'm not even going
            to try to correct them.

            To anyone reading this post: DON'T DO THIS.

            --
            Jack Klein
            Home: http://JK-Technology.Com
            FAQs for
            comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
            comp.lang.c++ http://www.parashift.com/c++-faq-lite/
            alt.comp.lang.l earn.c-c++

            Comment

            • Emmanuel Delahaye

              #7
              Re: 2 dimensional strcpy err

              Ross wrote on 25/12/04 :[color=blue]
              > char chain[10][300];
              >
              > strcpy(chain[i+20], chain[i]);
              >
              > error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
              > Conversion from integral type to pointer type requires
              > reinterpret_cas t, C-style cast or function-style cast[/color]

              First of all, be sure you are using a C compiler. The file extension
              should be .c (lowercase) and not .cpp or .C (uppercase).

              --
              Emmanuel
              The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
              The C-library: http://www.dinkumware.com/refxc.html

              "Clearly your code does not meet the original spec."
              "You are sentenced to 30 lashes with a wet noodle."
              -- Jerry Coffin in a.l.c.c++

              Comment

              • Andrey Tarasevich

                #8
                Re: 2 dimensional strcpy err

                Ross wrote:[color=blue]
                > char chain[10][300];
                >
                >
                > strcpy(chain[i+20], chain[i]);
                >
                >
                > error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
                > Conversion from integral type to pointer type requires
                > reinterpret_cas t, C-style cast or function-style cast
                >
                >
                > how to amend that?[/color]

                First of all - post real code. The code you provided cannot result in
                the above error message.

                --
                Best regards,
                Andrey Tarasevich

                Comment

                Working...