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