string to char array
I am trying to make a command interpreter for a mud that i am working
on the problem i am having right now is that i cannot convert the
string into a char array.
This is the error I am getting now:
In file included from src/mud.cpp:3:
src/command.h: In static member function `static void
command::getCommand(std::string)':
src/command.h:38: error: incompatible types in assignment of `const
char*' to `char[256]'
the third line is just an include statement for command.h
this is the code for command.h
#ifndef COMMAND_H
#define COMMAND_H
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;
class command {
public:
static void tokenizer(string str, vector<string>& words, string
delimiter);
static void getCommand(string c);
private:
static vector<string> cmd;
};
vector<string> command::cmd;
void command::tokenizer(string str, vector<string>& words, string
delimiter){
string::size_type pos1 = 0;
string::size_type pos2 = str.find_first_of(delimiter);
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
while(pos2 <= str.length()){
pos2 = str.find_first_of(delimiter, pos1);
if(pos2 > str.length()){
pos2 = str.length();
}
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
pos2 += 1;
}
}
void command::getCommand(string c){
tokenizer(c, cmd, " ");
if(cmd.size() == 1){
char oneWord[256];
oneWord = cmd[0].c_str();
for(int i = 0; oneWord.length; i++){
oneWord[i].toLower();
}
cmd[0] = oneWord;
// Move North
if(cmd[0] = "n" || cmd[0] = "north"){
}
// Move South
if(cmd[0] = "s" || cmd[0] = "south"){
}
// Move East
if(cmd[0] = "e" || cmd[0] = "east"){
}
// Move West
if(cmd[0] = "w" || cmd[0] = "west"){
}
// Move Up
if(cmd[0] = "u" || cmd[0] = "up"){
}
// Move Down
if(cmd[0] = "d" || cmd[0] = "down"){
}
} else if(cmd.size() == 2){
} else {
cout << "invalid command!\n";
}
}
#endif