Simple char array question

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2006
Posts: 187
Reputation: Matt Tacular is an unknown quantity at this point 
Solved Threads: 7
Matt Tacular's Avatar
Matt Tacular Matt Tacular is offline Offline
Unverified User

Simple char array question

 
0
  #1
Apr 4th, 2007
I am making a tic tac toe game, and for the grid, I had originally made 9 variables to represent the grid's spaces, but instead, I would now like to use a single char array. I can make the array and print certain parts, but I can't change them.

For example: char grid[] = "xoxoxoxox";

But then if i want to change the first entry to also be a "o", how would I do that? I tried
grid[0] = "o";
But it didn't work, it said invalid conversion from char to const char (possibly the other way around...)

Thanks everyone.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Simple char array question

 
0
  #2
Apr 4th, 2007
How about using grid[ 0 ] = 'o';
Last edited by WolfPack; Apr 4th, 2007 at 12:25 pm. Reason: Removed Original post Quote
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Simple char array question

 
0
  #3
Apr 4th, 2007
Double quoted literals are used to define strings, while single quoted literals for characters. Since you are creating an array of characters, you need to enclose the O in single and not double quotes like Wolfy has already said.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 45
Reputation: 7arouf is an unknown quantity at this point 
Solved Threads: 0
7arouf 7arouf is offline Offline
Light Poster

Re: Simple char array question

 
0
  #4
Apr 4th, 2007
i have no idea
i hope sombody will help
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Simple char array question

 
0
  #5
Apr 4th, 2007
Originally Posted by 7arouf View Post
i have no idea
i hope sombody will help
Two people already have -- Wolfie directly answering your question, SOS explaining something you need to understand. And here's a third:
TTT is played on a 3x3 grid, therefore you should consider using a 3x3 array (matrix), like char grid[3][3]
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC