Array of pointers

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

    Array of pointers

    I am creating an array of char pointers.

    char *str[2];
    str[1]= "ma";

    How ever the compiler gives me the following error. Any suggestions?

    error: expected constructor, destructor, or type conversion before '='
    token
    error: expected `,' or `;' before '=' token

  • pauldepstein@att.net

    #2
    Re: Array of pointers

    On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
    I am creating an array of char pointers.
    >
    char *str[2];
    str[1]= "ma";
    >
    How ever the compiler gives me the following error.  Any suggestions?
    >
    error: expected constructor, destructor, or type conversion before '='
    token
    error: expected `,' or `;' before '=' token
    I was mystified by this error too. So I tested it using Visual c++
    and Windows XP with a std::cout statement std::cout<<str[1]; for
    testing
    I got the string ma as expected.

    In other words, no this does not give any error on my machine. But
    you've obviously posted a snippet rather than the full code because,
    for example, there's no main. Could you please reproduce code in its
    entirety which generates the error?

    Paul Epstein

    Comment

    • Slain

      #3
      Re: Array of pointers

      On Mar 4, 9:56 pm, pauldepst...@at t.net wrote:
      On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
      >
      I am creating an array of char pointers.
      >
      char *str[2];
      str[1]= "ma";
      >
      How ever the compiler gives me the following error. Any suggestions?
      >
      error: expected constructor, destructor, or type conversion before '='
      token
      error: expected `,' or `;' before '=' token
      >
      I was mystified by this error too. So I tested it using Visual c++
      and Windows XP with a std::cout statement std::cout<<str[1]; for
      testing
      I got the string ma as expected.
      >
      In other words, no this does not give any error on my machine. But
      you've obviously posted a snippet rather than the full code because,
      for example, there's no main. Could you please reproduce code in its
      entirety which generates the error?
      >
      Paul Epstein
      I am declaring this as a global variable outside main. I use this
      later in a function

      int x= size/ strlen(str);
      for (int ii=0;ii<x; ii++)
      {
      strcat(String1, str);
      }

      Comment

      • Slain

        #4
        Re: Array of pointers

        On Mar 4, 9:56 pm, pauldepst...@at t.net wrote:
        On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
        >
        I am creating an array of char pointers.
        >
        char *str[2];
        str[1]= "ma";
        >
        How ever the compiler gives me the following error. Any suggestions?
        >
        error: expected constructor, destructor, or type conversion before '='
        token
        error: expected `,' or `;' before '=' token
        >
        I was mystified by this error too. So I tested it using Visual c++
        and Windows XP with a std::cout statement std::cout<<str[1]; for
        testing
        I got the string ma as expected.
        >
        In other words, no this does not give any error on my machine. But
        you've obviously posted a snippet rather than the full code because,
        for example, there's no main. Could you please reproduce code in its
        entirety which generates the error?
        >
        Paul Epstein
        I am declaring this as a global variable outside main. I use this
        later in a function

        int x= size/ strlen(str);
        for (int ii=0;ii<x; ii++)
        {
        strcat(String1, str);
        }

        Comment

        • Slain

          #5
          Re: Array of pointers

          On Mar 4, 9:56 pm, pauldepst...@at t.net wrote:
          On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
          >
          I am creating an array of char pointers.
          >
          char *str[2];
          str[1]= "ma";
          >
          How ever the compiler gives me the following error. Any suggestions?
          >
          error: expected constructor, destructor, or type conversion before '='
          token
          error: expected `,' or `;' before '=' token
          >
          I was mystified by this error too. So I tested it using Visual c++
          and Windows XP with a std::cout statement std::cout<<str[1]; for
          testing
          I got the string ma as expected.
          >
          In other words, no this does not give any error on my machine. But
          you've obviously posted a snippet rather than the full code because,
          for example, there's no main. Could you please reproduce code in its
          entirety which generates the error?
          >
          Paul Epstein
          I am declaring this as a global variable outside main. I use this
          later in a function

          int x= size/ strlen(str);
          for (int ii=0;ii<x; ii++)
          {
          strcat(String1, str);
          }

          Comment

          • pauldepstein@att.net

            #6
            Re: Array of pointers

            On Mar 5, 11:02 am, Slain <Slai...@gmail. comwrote:
            On Mar 4, 9:56 pm, pauldepst...@at t.net wrote:
            >
            >
            >
            >
            >
            On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
            >
            I am creating an array of char pointers.
            >
            char *str[2];
            str[1]= "ma";
            >
            How ever the compiler gives me the following error.  Any suggestions?
            >
            error: expected constructor, destructor, or type conversion before '='
            token
            error: expected `,' or `;' before '=' token
            >
            I was mystified by this error too.  So I tested it using Visual c++
            and Windows XP with a std::cout statement  std::cout<<str[1]; for
            testing
            I got the string ma as expected.
            >
            In other words, no this does not give any error on my machine.  But
            you've obviously posted a snippet rather than the full code because,
            for example, there's no main.  Could you please reproduce code in its
            entirety which generates the error?
            >
            Paul Epstein
            >
            I am declaring this as a global variable outside main. I use this
            later in a function
            >
            int x= size/  strlen(str);
                    for (int ii=0;ii<x; ii++)
                    {
                             strcat(String1, str);
                    }- Hide quoted text -
            >
            - Show quoted text -

            strlen(str) doesn't make sense to me. strlen means stringlength but
            str is not a string as you've defined it. I have no idea what you
            mean by strlen(str);

            Paul Epstein

            Comment

            • Slain

              #7
              Re: Array of pointers

              On Mar 4, 10:31 pm, pauldepst...@at t.net wrote:
              On Mar 5, 11:02 am, Slain <Slai...@gmail. comwrote:
              >
              >
              >
              On Mar 4, 9:56 pm, pauldepst...@at t.net wrote:
              >
              On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
              >
              I am creating an array of char pointers.
              >
              char *str[2];
              str[1]= "ma";
              >
              How ever the compiler gives me the following error. Any suggestions?
              >
              error: expected constructor, destructor, or type conversion before '='
              token
              error: expected `,' or `;' before '=' token
              >
              I was mystified by this error too. So I tested it using Visual c++
              and Windows XP with a std::cout statement std::cout<<str[1]; for
              testing
              I got the string ma as expected.
              >
              In other words, no this does not give any error on my machine. But
              you've obviously posted a snippet rather than the full code because,
              for example, there's no main. Could you please reproduce code in its
              entirety which generates the error?
              >
              Paul Epstein
              >
              I am declaring this as a global variable outside main. I use this
              later in a function
              >
              int x= size/ strlen(str);
              for (int ii=0;ii<x; ii++)
              {
              strcat(String1, str);
              }- Hide quoted text -
              >
              - Show quoted text -
              >
              strlen(str) doesn't make sense to me. strlen means stringlength but
              str is not a string as you've defined it. I have no idea what you
              mean by strlen(str);
              >
              Paul Epstein
              Yes!!! That part of the code was before I tried to make str an array
              if pointers. When I used the strlen I just used the str as a char
              pointer.

              Thanks
              manny

              Comment

              • Ian Collins

                #8
                Re: Array of pointers

                Slain wrote:
                >
                Yes!!! That part of the code was before I tried to make str an array
                if pointers. When I used the strlen I just used the str as a char
                pointer.
                >
                Is there a good reason why you can't use std::string?


                --
                Ian Collins.

                Comment

                • pauldepstein@att.net

                  #9
                  Re: Array of pointers

                  On Mar 5, 11:34 am, Slain <Slai...@gmail. comwrote:
                  On Mar 4, 10:31 pm, pauldepst...@at t.net wrote:
                  >
                  >
                  >
                  >
                  >
                  On Mar 5, 11:02 am, Slain <Slai...@gmail. comwrote:
                  >
                  On Mar 4, 9:56 pm, pauldepst...@at t.net wrote:
                  >
                  On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
                  >
                  I am creating an array of char pointers.
                  >
                  char *str[2];
                  str[1]= "ma";
                  >
                  How ever the compiler gives me the following error.  Any suggestions?
                  >
                  error: expected constructor, destructor, or type conversion before'='
                  token
                  error: expected `,' or `;' before '=' token
                  >
                  I was mystified by this error too.  So I tested it using Visual c++
                  and Windows XP with a std::cout statement  std::cout<<str[1]; for
                  testing
                  I got the string ma as expected.
                  >
                  In other words, no this does not give any error on my machine.  But
                  you've obviously posted a snippet rather than the full code because,
                  for example, there's no main.  Could you please reproduce code in its
                  entirety which generates the error?
                  >
                  Paul Epstein
                  >
                  I am declaring this as a global variable outside main. I use this
                  later in a function
                  >
                  int x= size/  strlen(str);
                          for (int ii=0;ii<x; ii++)
                          {
                                   strcat(String1, str);
                          }- Hide quoted text -
                  >
                  - Show quoted text -
                  >
                  strlen(str)  doesn't make sense to me.  strlen means stringlength but
                  str is not a string as you've defined it.  I have no idea what you
                  mean by strlen(str);
                  >
                  Paul Epstein
                  >
                  Yes!!! That part of the code was before I tried to make str an array
                  if pointers. When I used the strlen I just used the str as a char
                  pointer.
                  >
                  Thanks
                  manny- Hide quoted text -
                  >
                  - Show quoted text -
                  I don't understand why you say "Yes!!!" What question are you
                  answering "Yes!!!" to? It seems that "Yes!!!" should be replaced by
                  "Sorry for the confusion I caused."


                  Paul Epstein

                  Comment

                  • faizulhaquezeya@gmail.com

                    #10
                    Re: Array of pointers

                    On Mar 5, 7:34 am, Slain <Slai...@gmail. comwrote:
                    I am creating an array of char pointers.
                    >
                    char *str[2];
                    str[1]= "ma";
                    >
                    How ever the compiler gives me the following error.  Any suggestions?
                    >
                    error: expected constructor, destructor, or type conversion before '='
                    token
                    error: expected `,' or `;' before '=' token
                    you are not allocating memory for that.
                    faiz ul haque zeya
                    Transys

                    Comment

                    • pelio

                      #11
                      Re: Array of pointers

                      Slain dixit:
                      On Mar 4, 9:56 pm, pauldepst...@at t.net wrote:
                      >On Mar 5, 10:34 am, Slain <Slai...@gmail. comwrote:
                      >>
                      >>I am creating an array of char pointers.
                      >>char *str[2];
                      >>str[1]= "ma";
                      >>How ever the compiler gives me the following error. Any suggestions?
                      >>error: expected constructor, destructor, or type conversion before '='
                      >>token
                      >>error: expected `,' or `;' before '=' token
                      >I was mystified by this error too. So I tested it using Visual c++
                      >and Windows XP with a std::cout statement std::cout<<str[1]; for
                      >testing
                      >I got the string ma as expected.
                      >>
                      >In other words, no this does not give any error on my machine. But
                      >you've obviously posted a snippet rather than the full code because,
                      >for example, there's no main. Could you please reproduce code in its
                      >entirety which generates the error?
                      >>
                      >Paul Epstein
                      >
                      I am declaring this as a global variable outside main. I use this
                      later in a function

                      If your code is like that:

                      char *str[2]; // line 1
                      str[1] = "ma"; // line 2

                      // ...

                      int main()
                      {
                      }

                      be aware that line 2 is illegal.
                      >
                      int x= size/ strlen(str);
                      for (int ii=0;ii<x; ii++)
                      {
                      strcat(String1, str);
                      }
                      >

                      Comment

                      Working...