Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I get an error I don't know about?

Posted on 2004-03-30
4
Medium Priority
?
213 Views
Last Modified: 2010-04-01
Hi, I've just started C++ Programming and I was looking through arrays and well, I have a 3 x 3 char array and I want to make it blank:

01  char Board[3][3];
02  char a = " ";
03   for(int i = 0; i < 3; i++)
04   {
05    for(int j = 0; j > 3; j++)
06    {
07     Board[i][j] = a;
08    }
09   }

I haven't been able to see what's wrong with this but I keep getting the msg,

Line 02: initialization to 'char' from 'const char *' lacks a cast

I'm using the Bloodshed C++ v4.01 compiler to do this (if it's important) on a windows XP platform...

I'm just wondering what's wrong? if someone could explain what's wrong along with any sort of corrections? thanks in advance...
0
Comment
Question by:johnnytee
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 200 total points
ID: 10711713
>> char a = " ";
should be

char a = ' ' ;

Double quotes is treated as a char string in C/C++
To specify a character, use Single quotes


Amit
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10711721
Also, no need to run a for loop if u are initializing the array elements with a single value
Just use this

 char Board[3][3] = { ' ' } ;


Amit
0
 
LVL 16

Expert Comment

by:nonubik
ID: 10711737
Maybe you should do:
02 char a = ' ';  //with ' instead of "

And I think in line 05 should be j<3 instead of j>3 . Otherwise it will enter only once in your for(j) loop.
0
 

Author Comment

by:johnnytee
ID: 10711739
oh i thank you for that. concise and well explained.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question