By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

Array of pointers

P: n/a
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

Mar 5 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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
Mar 5 '08 #2

P: n/a
On Mar 4, 9:56 pm, pauldepst...@att.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);
}

Mar 5 '08 #3

P: n/a
On Mar 4, 9:56 pm, pauldepst...@att.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);
}

Mar 5 '08 #4

P: n/a
On Mar 4, 9:56 pm, pauldepst...@att.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);
}

Mar 5 '08 #5

P: n/a
On Mar 5, 11:02*am, Slain <Slai...@gmail.comwrote:
On Mar 4, 9:56 pm, pauldepst...@att.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
Mar 5 '08 #6

P: n/a
On Mar 4, 10:31 pm, pauldepst...@att.net wrote:
On Mar 5, 11:02 am, Slain <Slai...@gmail.comwrote:
On Mar 4, 9:56 pm, pauldepst...@att.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
Mar 5 '08 #7

P: n/a
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.
Mar 5 '08 #8

P: n/a
On Mar 5, 11:34*am, Slain <Slai...@gmail.comwrote:
On Mar 4, 10:31 pm, pauldepst...@att.net wrote:


On Mar 5, 11:02 am, Slain <Slai...@gmail.comwrote:
On Mar 4, 9:56 pm, pauldepst...@att.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
Mar 5 '08 #9

P: n/a
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
Mar 5 '08 #10

P: n/a
Slain dixit:
On Mar 4, 9:56 pm, pauldepst...@att.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);
}
Mar 5 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.