LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2004, 07:22 PM   #1
Kane635
Member
 
Registered: Jul 2004
Posts: 36

Rep: Reputation: 15
C++ hackers anyone?


#include <iostream.h>
using namespace std;

void initVars()
{
char board[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
}

void displayBoard()
{
cout << " | | " << endl;
cout << " " << board[0] << " | " << board[1] << " | " << board[2] << " " << endl;
cout << "---|---|---" << endl;
cout << " " << board[3] << " | " << board[4] << " | " << board[5] << " " << endl;
cout << "---|---|---" << endl;
cout << " " << board[6] << " | " << board[7] << " | " << board[8] << " " << endl;
cout << " | | " << endl;
}

int main()
{
initVars();
displayBoard();
cin.ignore();
}

12 C:\Dev-Cpp\Untitled1.cpp `board' undeclared (first use this function)
 
Old 10-04-2004, 07:30 PM   #2
Kane635
Member
 
Registered: Jul 2004
Posts: 36

Original Poster
Rep: Reputation: 15
declaring board[8] gives...
6 C:\Dev-Cpp\Untitled1.cpp too many initializers for `char[8]'
 
Old 10-04-2004, 07:37 PM   #3
tim1235
Member
 
Registered: Aug 2004
Location: Melbourne, Australia
Distribution: fc5/Gentoo
Posts: 57

Rep: Reputation: 15
12 C:\Dev-Cpp\Untitled1.cpp `board' undeclared (first use this function)

You declare a board in InitVars() but don't do anything with it!

In you function main you call InitVars which creates a board array but then returns nothing! (void function). Your function displayBoard() then tries to use an unknown variable board. It either has to be passed to this function, or the board variable must be global.

You should either declare a global board or get you function InitVars to return the initalised board and then do something with it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
calling all hackers evilmonk Linux - Software 4 03-12-2005 10:13 PM
Who are hackers? cyto General 10 12-24-2004 11:17 AM
Hackers consty Linux - Security 17 08-26-2004 06:52 AM
According to this we are all hackers bubba169 General 10 05-03-2004 10:59 PM
any X hackers? deepsix Programming 0 09-13-2003 11:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration