Oy mates, I'm sucking it up lately. This should be a quick solve for someone who knows whats going on (or who can find an example that deals with it that is diff from what I've done)
Basically a command comes in, depending on the command I need to do different things. so if the user types "hello and then anything here for long time" I would want to go to one case and run a particular function (based on the first word 'hello').
You cannot use strings on switch/case statements. Anyway, to fix that you would have to make a splitter function that would split at the first space (or at a certain character length) and then (probably) return the string of the first word (characters). Then you can check that with ifs/else ifs and do whatever else you need to.
1 2 3 4 5 6 7 8 9 10 11
//something like this
void handlemsg(string message) {
string buffer = split(message);
if (buffer == "hello") {
//hello
} elseif(buffer == "lol") {
//lol
} else {
//...
}
}
Well, I saw an example online where somebody supposedly did it, but it didn't work for me. So i think there must be a way to do it, but regardless:
the way i would do you're solution is to use the function strncmp i mentioned above. compare so many characters of each string. int count = strcspn(buffer," ") returns the number of chars till the first space, so then you'd call if(strncmp(buffer,"hello",count)==0) essentially.