Invalid conversion from 'char' tp 'char*'

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

    #16
    Re: Invalid conversion from 'char' tp 'char*'

    Christopher Benson-Manica wrote:
    [color=blue]
    > Tim Johansson <spam@gurka.s e> spoke thus:
    >
    >[color=green]
    >>#include <iostream.h>[/color]
    >
    >
    > It's called <iostream> - the .h headers are deprecated.
    >[/color]

    It's true that those headers which are part of the standard and which
    end in .h are deprecated, but <iostream.h> is not even part of the
    standard, therefore cannot be deprecated.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.

    Comment

    • Kevin Goodsell

      #17
      Re: Invalid conversion from 'char' tp 'char*'

      Christopher Benson-Manica wrote:
      [color=blue]
      > Tim Johansson <spam@gurka.s e> spoke thus:
      >
      >[color=green]
      >>#include <iostream.h>[/color]
      >
      >
      > It's called <iostream> - the .h headers are deprecated.
      >[/color]

      It's true that those headers which are part of the standard and which
      end in .h are deprecated, but <iostream.h> is not even part of the
      standard, therefore cannot be deprecated.

      -Kevin
      --
      My email address is valid, but changes periodically.
      To contact me please use the address from a recent posting.

      Comment

      • Christopher Benson-Manica

        #18
        Re: Invalid conversion from 'char' tp 'char*'

        Kevin Goodsell <usenet2.spamfr ee.fusion@never box.com> spoke thus:
        [color=blue]
        > It's true that those headers which are part of the standard and which
        > end in .h are deprecated, but <iostream.h> is not even part of the
        > standard, therefore cannot be deprecated.[/color]

        Clearly my answer was deprecated - sorry :)

        --
        Christopher Benson-Manica | I *should* know what I'm talking about - if I
        ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

        Comment

        • Christopher Benson-Manica

          #19
          Re: Invalid conversion from 'char' tp 'char*'

          Kevin Goodsell <usenet2.spamfr ee.fusion@never box.com> spoke thus:
          [color=blue]
          > It's true that those headers which are part of the standard and which
          > end in .h are deprecated, but <iostream.h> is not even part of the
          > standard, therefore cannot be deprecated.[/color]

          Clearly my answer was deprecated - sorry :)

          --
          Christopher Benson-Manica | I *should* know what I'm talking about - if I
          ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

          Comment

          • Jack Klein

            #20
            Re: Invalid conversion from 'char' tp 'char*'

            On Wed, 7 Apr 2004 20:35:28 +0000 (UTC), Christopher Benson-Manica
            <ataru@nospam.c yberspace.org> wrote in comp.lang.c++:
            [color=blue]
            > Tim Johansson <spam@gurka.s e> spoke thus:
            >[color=green]
            > > #include <iostream.h>[/color]
            >
            > It's called <iostream> - the .h headers are deprecated.
            >[color=green]
            > > #include <string.h>[/color]
            >[color=green]
            > > int main () {
            > > srand(time(0));
            > > int array_length;
            > > int count;
            > > int randm;
            > > char temp[30];
            > > cout << "How many items in array? ";
            > > cin >> array_length;
            > > char items [30][array_length + 1];[/color]
            > ^^^^^^^^^^^^
            > I assume this is legal in C++, but I'd love it if a real C++ person
            > stated something authoratative. As an aside, if you're making the
            > array array_length+1 items long, then array_length isn't really, is
            > it?[/color]

            No, it is not legal in C++. It is legal in C under the
            not-widely-implemented C99 version of the standard, where arrays with
            automatic storage class can be VLAs (Variable Length Arrays). It is
            also a non-standard extension provided by GNU and perhaps other
            compilers.

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

            • Jack Klein

              #21
              Re: Invalid conversion from 'char' tp 'char*'

              On Wed, 7 Apr 2004 20:35:28 +0000 (UTC), Christopher Benson-Manica
              <ataru@nospam.c yberspace.org> wrote in comp.lang.c++:
              [color=blue]
              > Tim Johansson <spam@gurka.s e> spoke thus:
              >[color=green]
              > > #include <iostream.h>[/color]
              >
              > It's called <iostream> - the .h headers are deprecated.
              >[color=green]
              > > #include <string.h>[/color]
              >[color=green]
              > > int main () {
              > > srand(time(0));
              > > int array_length;
              > > int count;
              > > int randm;
              > > char temp[30];
              > > cout << "How many items in array? ";
              > > cin >> array_length;
              > > char items [30][array_length + 1];[/color]
              > ^^^^^^^^^^^^
              > I assume this is legal in C++, but I'd love it if a real C++ person
              > stated something authoratative. As an aside, if you're making the
              > array array_length+1 items long, then array_length isn't really, is
              > it?[/color]

              No, it is not legal in C++. It is legal in C under the
              not-widely-implemented C99 version of the standard, where arrays with
              automatic storage class can be VLAs (Variable Length Arrays). It is
              also a non-standard extension provided by GNU and perhaps other
              compilers.

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

              • Old Wolf

                #22
                Re: Invalid conversion from 'char' tp 'char*'

                Christopher Benson-Manica <ataru@nospam.c yberspace.org> wrote:[color=blue]
                > Tim Johansson <spam@gurka.s e> spoke thus:
                >[color=green]
                > > char items [30][array_length + 1];[/color]
                > ^^^^^^^^^^^^
                > I assume this is legal in C++, but I'd love it if a real C++ person
                > stated something authoratative. As an aside, if you're making the
                > array array_length+1 items long, then array_length isn't really, is
                > it?[/color]

                Well it isn't the array length anyway: he would have declared an array
                of 30 items, each item of which has length (array_length+1 ), if the
                syntax were legal.
                [color=blue][color=green]
                > > for (count = 0; count < array_length; count++) {
                > > randm = rand() % array_length;
                > > strcpy (temp[30], items[30][count]);[/color]
                >
                > Here's the problem (well, besides that you're using C-style strings at
                > all): strcpy is prototyped as
                >
                > char *strcpy( char *s, const char *t );
                >
                > What is temp[30]? It's a char, of course. And what is
                > items[30][count]? It's a char, too. No wonder it doesn't compile,
                > eh?[/color]

                Not to mention that both are undefined behaviour (reading a char
                from past the end of the array). God knows what he was trying to do there.
                [color=blue]
                > Either read a C book or learn how to use std::strings and std::vectors
                > - I recommend the latter.[/color]

                Seeing code like this is what moved me from the "Learn C then C++" camp
                to the "Learn C++ then C" camp. Petec's replacement program is
                excellent.

                Comment

                • Old Wolf

                  #23
                  Re: Invalid conversion from 'char' tp 'char*'

                  Christopher Benson-Manica <ataru@nospam.c yberspace.org> wrote:[color=blue]
                  > Tim Johansson <spam@gurka.s e> spoke thus:
                  >[color=green]
                  > > char items [30][array_length + 1];[/color]
                  > ^^^^^^^^^^^^
                  > I assume this is legal in C++, but I'd love it if a real C++ person
                  > stated something authoratative. As an aside, if you're making the
                  > array array_length+1 items long, then array_length isn't really, is
                  > it?[/color]

                  Well it isn't the array length anyway: he would have declared an array
                  of 30 items, each item of which has length (array_length+1 ), if the
                  syntax were legal.
                  [color=blue][color=green]
                  > > for (count = 0; count < array_length; count++) {
                  > > randm = rand() % array_length;
                  > > strcpy (temp[30], items[30][count]);[/color]
                  >
                  > Here's the problem (well, besides that you're using C-style strings at
                  > all): strcpy is prototyped as
                  >
                  > char *strcpy( char *s, const char *t );
                  >
                  > What is temp[30]? It's a char, of course. And what is
                  > items[30][count]? It's a char, too. No wonder it doesn't compile,
                  > eh?[/color]

                  Not to mention that both are undefined behaviour (reading a char
                  from past the end of the array). God knows what he was trying to do there.
                  [color=blue]
                  > Either read a C book or learn how to use std::strings and std::vectors
                  > - I recommend the latter.[/color]

                  Seeing code like this is what moved me from the "Learn C then C++" camp
                  to the "Learn C++ then C" camp. Petec's replacement program is
                  excellent.

                  Comment

                  • John Harrison

                    #24
                    Re: Invalid conversion from 'char' tp 'char*'

                    Kevin, someone should be paying you.

                    john


                    Comment

                    • John Harrison

                      #25
                      Re: Invalid conversion from 'char' tp 'char*'

                      Kevin, someone should be paying you.

                      john


                      Comment

                      • John Harrison

                        #26
                        Re: Invalid conversion from 'char' tp 'char*'


                        "Tim Johansson" <spam@gurka.s e> wrote in message
                        news:c51l09$2no sfd$1@ID-224346.news.uni-berlin.de...[color=blue]
                        > I'm new to C++, and tried to start making a script that will shuffle an
                        > array. Can someone please tell me what's wrong?
                        >[/color]

                        You've been give lots of good advice, but clearly the best advice is to find
                        better material for your learning.

                        1) Get a good book, one that doesn't say that <iostream.h> is the right
                        thing to do. Also one that mentions standard library templates such as
                        string and vector (these are what you should be using for this program).

                        2) Get a better compiler. The compiler you are using is allowing you to get
                        away with illegal code. What sort of way to learn C++ is that? Now I'm
                        guessing here but if you are using gcc or g++ then you should compile with
                        the -ansi and -pedantic options. This will make your compiler much closer to
                        the real C++ language.

                        john


                        Comment

                        • John Harrison

                          #27
                          Re: Invalid conversion from 'char' tp 'char*'


                          "Tim Johansson" <spam@gurka.s e> wrote in message
                          news:c51l09$2no sfd$1@ID-224346.news.uni-berlin.de...[color=blue]
                          > I'm new to C++, and tried to start making a script that will shuffle an
                          > array. Can someone please tell me what's wrong?
                          >[/color]

                          You've been give lots of good advice, but clearly the best advice is to find
                          better material for your learning.

                          1) Get a good book, one that doesn't say that <iostream.h> is the right
                          thing to do. Also one that mentions standard library templates such as
                          string and vector (these are what you should be using for this program).

                          2) Get a better compiler. The compiler you are using is allowing you to get
                          away with illegal code. What sort of way to learn C++ is that? Now I'm
                          guessing here but if you are using gcc or g++ then you should compile with
                          the -ansi and -pedantic options. This will make your compiler much closer to
                          the real C++ language.

                          john


                          Comment

                          • Kevin Goodsell

                            #28
                            Re: Invalid conversion from 'char' tp 'char*'

                            John Harrison wrote:
                            [color=blue]
                            > Kevin, someone should be paying you.
                            >
                            > john
                            >
                            >[/color]

                            Well, I certainly think so. ;) But not for what I'm doing here. I think
                            we all do this for basically the same reason: because learning is hard,
                            because we want to see the overall quality of programmers improve, and
                            because we want to give back to the group that is always here to help us
                            when we need it.

                            -Kevin
                            --
                            My email address is valid, but changes periodically.
                            To contact me please use the address from a recent posting.

                            Comment

                            • Kevin Goodsell

                              #29
                              Re: Invalid conversion from 'char' tp 'char*'

                              John Harrison wrote:
                              [color=blue]
                              > Kevin, someone should be paying you.
                              >
                              > john
                              >
                              >[/color]

                              Well, I certainly think so. ;) But not for what I'm doing here. I think
                              we all do this for basically the same reason: because learning is hard,
                              because we want to see the overall quality of programmers improve, and
                              because we want to give back to the group that is always here to help us
                              when we need it.

                              -Kevin
                              --
                              My email address is valid, but changes periodically.
                              To contact me please use the address from a recent posting.

                              Comment

                              • Christopher Benson-Manica

                                #30
                                Re: Invalid conversion from 'char' tp 'char*'

                                Kevin Goodsell <usenet2.spamfr ee.fusion@never box.com> spoke thus:
                                [color=blue]
                                > Well, I certainly think so. ;) But not for what I'm doing here. I think
                                > we all do this for basically the same reason: because learning is hard,
                                > because we want to see the overall quality of programmers improve, and
                                > because we want to give back to the group that is always here to help us
                                > when we need it.[/color]

                                You forgot some reasons: learning is fun, writing elegant code is fun,
                                and engaging in arcane pedantry is fun ;)

                                --
                                Christopher Benson-Manica | I *should* know what I'm talking about - if I
                                ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

                                Comment

                                Working...