Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Array of pointers

Reply
Thread Tools

Array of pointers

 
 
Slain
Guest
Posts: n/a
 
      03-05-2008
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

 
Reply With Quote
 
 
 
 
pauldepstein@att.net
Guest
Posts: n/a
 
      03-05-2008
On Mar 5, 10:34*am, Slain <Slai...@gmail.com> wrote:
> 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
 
Reply With Quote
 
 
 
 
Slain
Guest
Posts: n/a
 
      03-05-2008
On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
> On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:
>
> > 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);
}

 
Reply With Quote
 
Slain
Guest
Posts: n/a
 
      03-05-2008
On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
> On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:
>
> > 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);
}

 
Reply With Quote
 
Slain
Guest
Posts: n/a
 
      03-05-2008
On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
> On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:
>
> > 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);
}

 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      03-05-2008
On Tue, 4 Mar 2008 19:07:49 -0800 (PST), Slain <>
wrote in comp.lang.c++:

> On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
> > On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:
> >
> > > I am creating an array of char pointers.

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


Now that you have finally given us the important information, below,
that is at namespace scope, we can tell you what the problem is.

The second line is an assignment, which is an executable statement.
Executable statements can only appear inside functions, not at file
scope.

You can initialize in a declaration at file scope:

char *str [2] = { "whatever", "ma" };

Otherwise, you can define the array without initialization, both
pointers will be set to NULL, and then change their contents with
assignments inside a function.

> > > 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);
> }


--
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.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-05-2008
* Slain:
> On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
>> On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:
>>
>>> 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);
> }


Why don't you /read/ Paul's article, in particular the last paragraph,
that you responded to and quoted above?

Just to help you with this I'll quote the very last sentence again:


>> Could you please reproduce code in its
>> entirety which generates the error?



The code you posted first time was incomplete and sans relevant context.

The code you posted this time suffered from both those, plus was
inconsistent with the earlier code.

Third time,


>> Could you please reproduce code in its
>> entirety which generates the error?




Cheers, & hth.,

- Alf

PS: How to post a question about Code That Does Not Work As Expected is
a FAQ item. Please do read the FAQ. /Before/ posting.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Slain
Guest
Posts: n/a
 
      03-05-2008
On Mar 4, 10:26 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * Slain:
>
>
>
> > On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
> >> On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:

>
> >>> 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);
> > }

>
> Why don't you /read/ Paul's article, in particular the last paragraph,
> that you responded to and quoted above?
>
> Just to help you with this I'll quote the very last sentence again:
>
> >> Could you please reproduce code in its
> >> entirety which generates the error?

>
> The code you posted first time was incomplete and sans relevant context.
>
> The code you posted this time suffered from both those, plus was
> inconsistent with the earlier code.
>
> Third time,
>
> >> Could you please reproduce code in its
> >> entirety which generates the error?

>
> Cheers, & hth.,
>
> - Alf
>
> PS: How to post a question about Code That Does Not Work As Expected is
> a FAQ item. Please do read the FAQ. /Before/ posting.
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?


Sorry Alf, This was my second time here I guess. I couldnt post the
whole code due to the big size. How ever I later did add the
information that it is a global variable. I guess thats the part I
should have added.

Thanks to jack, Hopefully this should work.
 
Reply With Quote
 
pauldepstein@att.net
Guest
Posts: n/a
 
      03-05-2008
On Mar 5, 11:02*am, Slain <Slai...@gmail.com> wrote:
> On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
>
>
>
>
>
> > On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:

>
> > > 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
 
Reply With Quote
 
Slain
Guest
Posts: n/a
 
      03-05-2008
On Mar 4, 10:26 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * Slain:
>
>
>
> > On Mar 4, 9:56 pm, pauldepst...@att.net wrote:
> >> On Mar 5, 10:34 am, Slain <Slai...@gmail.com> wrote:

>
> >>> 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);
> > }

>
> Why don't you /read/ Paul's article, in particular the last paragraph,
> that you responded to and quoted above?
>
> Just to help you with this I'll quote the very last sentence again:
>
> >> Could you please reproduce code in its
> >> entirety which generates the error?

>
> The code you posted first time was incomplete and sans relevant context.
>
> The code you posted this time suffered from both those, plus was
> inconsistent with the earlier code.
>
> Third time,
>
> >> Could you please reproduce code in its
> >> entirety which generates the error?

>
> Cheers, & hth.,
>
> - Alf
>
> PS: How to post a question about Code That Does Not Work As Expected is
> a FAQ item. Please do read the FAQ. /Before/ posting.
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?


Sorry Alf, This was my second time here I guess. I couldnt post the
whole code due to the big size. How ever I later did add the
information that it is a global variable. I guess thats the part I
should have added.

Thanks to jack, Hopefully this should work.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
pointers and array of pointers Piotrek C Programming 8 04-06-2007 08:02 AM
Pointers, linked list, array of pointers Sean C++ 2 09-24-2006 01:35 PM
pointer to array v/s array of pointers mann! C Programming 6 02-26-2005 12:59 AM
Can a static array contain a dynamic array of pointers? Peter B. Steiger C Programming 8 04-26-2004 03:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57