Question: Hello I'm working with an AR Camera and once the camera identifies the anchored image it plays the video. Once the video finishes playing and return back to the camera I view the same anchored image again the video does not play. I want to be able to view the image and play the video as many times as possible. 

***Here is my function to play the video.***

```
    func playVideo() {
    guard let videoLink = URL(string: "string") else {
        return
    }
    DispatchQueue.main.async {
        let player = AVPlayer(url: videoLink)
        let controller = AVPlayerViewController()
        controller.player = player
            self.present(controller, animated: true){
               player.play()
           }
        }
}

```

***Here is my function to recognize the image.***

```
    func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
    if let imageAnchor = anchor as? ARImageAnchor{
        switch imageAnchor.name{
        case "image":
            playVideo()
        default:
            break
        }
    }
    return nil
}

```

Can someone help me out or point me in the right direction to figure this out?

Answer: 
Your function is too complicated and it returns `0` if the suffix is `OH`. A simpler way is to compute the length of the string and if this length is at least 2, compare the last 2 characters with `'O'` and `'H'`:

```c
int hydroxide(const char *string) {
    size_t len = strlen(string);
    if (len >= 2 && string[len - 2] == 'O'  && string[len - 1] == 'H')
        return -1;
    else
        return 0;
}

```

Furthermore, the `main` function has undefined behavior: `string` is an uninitialized `char` pointer: passing it to `gets()` will cause undefined behavior when `gets()` tries to write bytes to it. Note also that `gets()` is obsolete and has been removed from the latest version of the C Standard because there is no way to prevent a buffer overflow for sufficiently long input strings. Use `fgets()` instead and remove the trailing newline, if any:

Here is a modified version:

```c
#include <stdio.h>
#include <string.h>

int hydroxide(const char *string) {
    size_t len = strlen(string);
    if (len >= 2 && string[len - 2] == 'O'  && string[len - 1] == 'H')
        return -1;
    else
        return 0;
}

int main() {
    char buf[80];
    printf("Enter String: ");
    if (fgets(buf, sizeof buf, stdin)) {
        buf[strcspn(buf, "\n")] = '\0';  // strip the newline if any
        printf("%d\n", hydroxide(string));
    }
    return 0;
}

```
Get the length of the string and check the last two characters.

```
int len = strlen(string);
      if(string[len-1] == 'H' && string[len-2] =='O')
          return -1;

```