I am making a text-based rpg as a final project for grade 11 academic computer sciences and my teacher noticed my character array as..
char chrKnightAttacks[100] = {'1 - Attack\n'}; (there is ALOT more i dont need to put here.
What i was trying to do was wait for a variable to be declared as a 1 in a later if statement and that could for example turn the array into
char chrKnightAttacks[100] = {1 - Attack\n2 - Judgement\n};
Ofcourse there were the errors that could not be fixed easily
He told me i needed to split the character array into single parts like so..
char chrKnightAttacks[100] = {'1',' ','-',' ','A','t','t','a','c','k','\',' ','n','2',' ','-',' ','J','u','d','g','e','m','e','n','t','\','n'};
I got the following warnings/errors...
75:71 E:\ICS3U1_Erik5730\Games\TEXTRPG\TEXTRPG2\Main.cpp [Warning] multi-character character constant
75 E:\ICS3U1_Erik5730\Games\TEXTRPG\TEXTRPG2\Main.cpp expected `}' before "n"
75 E:\ICS3U1_Erik5730\Games\TEXTRPG\TEXTRPG2\Main.cpp expected `,' or `;' before "n"
and
75 E:\ICS3U1_Erik5730\Games\TEXTRPG\TEXTRPG2\Main.cpp stray '\' in program
apparently it doesn't like that fact that im ending the line in my array but this is the only way the spells would be listed like
1 - Attack
2 - Judgement
etc.
When it wasnt split into seperate parts the array did in fact end the line.
Is there a possible easy way out here?
Splitting A character array into separate charactersUsing \n in a character array
Page 1 of 1
4 Replies - 2528 Views - Last Post: 07 January 2010 - 05:40 PM
#1
Splitting A character array into separate characters
Posted 07 January 2010 - 05:19 PM
Replies To: Splitting A character array into separate characters
#2
Re: Splitting A character array into separate characters
Posted 07 January 2010 - 05:23 PM
When you declare it like that you need double quotes since it's a "string". (a C style string, but a string nevertheless).
Could you explain what exactly you want? You want menu options to be updated/offered on the fly?
Could you explain what exactly you want? You want menu options to be updated/offered on the fly?
#3
Re: Splitting A character array into separate characters
Posted 07 January 2010 - 05:23 PM
Well one problem i spy is that you should have \n as not '\' 'n' but '\n'. It is one character.
That's why you get this error:
75 E:\ICS3U1_Erik5730\Games\TEXTRPG\TEXTRPG2\Main.cpp stray '\' in program
That's why you get this error:
75 E:\ICS3U1_Erik5730\Games\TEXTRPG\TEXTRPG2\Main.cpp stray '\' in program
This post has been edited by Astraeus: 07 January 2010 - 05:24 PM
#4
Re: Splitting A character array into separate characters
Posted 07 January 2010 - 05:25 PM
I want it so when you say choose a skill the code detects that, and adds that skill into the array so it outputs on the screen. If say you haven't chosen it, it doesn't output and it will just be the number with a blank space. I know it's confusing but i always seem to take the complicated route in things.
#5
Re: Splitting A character array into separate characters
Posted 07 January 2010 - 05:40 PM
So what about doing a cin or a getline for the action and using an if statement?
And then maybe for the skills you could try using a class. Unless you don't want it turn based then you'd need to use a function to get keys I am not sure what it is.
And then maybe for the skills you could try using a class. Unless you don't want it turn based then you'd need to use a function to get keys I am not sure what it is.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|