Solved

I get an error I don't know about?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

710 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