Solved

I get an error I don't know about?

Posted on 2004-03-30
4
208 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 50 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

773 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