Check if char contains certain word

I have a little software program, where I do an API call to retrieve the name of a device that's assigned on a server. Every once in a while though, a glitch occurs and it fetches a semi-random series of characters and numbers. Ideally, I'd want to tackle the source of this problem, but as of date I haven't found any information on why this glitch may occassionally be happening. Therefore, I simply want to instruct the device to re-do the API call to fix this issue.

The variable is defined as char deviceName[64]. When it glitches out, the name it fetches always starts with the word talwrite. The easiest solution IMO would be to set up an if-statement, and if the fetched name includes the word talwrite, it'll re-do the API call.

How should I set this if-statement?
Last edited on
Many options. Here's one:

1
2
3
4
5
6
std::string temp(deviceName); // create a std string
if (temp.find("talwrite") == 0) // if "talwrite" begins at location 0 of string i.e. at start of string
{
  // redo API call

}
You haven’t shown us any code, but you can use the C strstr() function or you can use a std::string and s.find("talwrite").
Topic archived. No new replies allowed.