4 Replies - 3391 Views - Last Post: 07 January 2010 - 05:40 PM Rate Topic: -----

#1 Zerilis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

Splitting A character array into separate characters

Post icon  Posted 07 January 2010 - 05:19 PM

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?

Is This A Good Question/Topic? 0
  • +

Replies To: Splitting A character array into separate characters

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,140
  • Joined: 14-September 07

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?
Was This Post Helpful? 1
  • +
  • -

#3 Astraeus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 205
  • Joined: 17-November 09

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

This post has been edited by Astraeus: 07 January 2010 - 05:24 PM

Was This Post Helpful? 1
  • +
  • -

#4 Zerilis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

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.
Was This Post Helpful? 0
  • +
  • -

#5 Chaos Mange  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 68
  • Joined: 23-December 09

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1