How to compare arrays of char in CUDA C++?

前端 未结 1 1041
无人共我
无人共我 2020-12-18 15:35

I need a function in cuda that recieves an array of chars and if they match, the function returns a value, but when i test this code, always return 0, like none of these con

相关标签:
1条回答
  • 2020-12-18 15:56

    How about this:

    __device__ int my_strcmp(const char *str_a, const char *str_b, unsigned len = 256){
      int match = 0;
      unsigned i = 0;
      unsigned done = 0;
      while ((i < len) && (match == 0) && !done){
        if ((str_a[i] == 0) || (str_b[i] == 0)) done = 1;
        else if (str_a[i] != str_b[i]){
          match = i+1;
          if ((int)str_a[i] - (int)str_b[i]) < 0) match = 0 - (i + 1);}
        i++;}
      return match;
      }
    
    0 讨论(0)
提交回复
热议问题