Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I get an error I don't know about?

Posted on 2004-03-30
4
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

704 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