如何比较两个char *变量变量、两个、char

2023-09-11 23:26:26 作者:感情待我如此薄

假设我们有下面的方法(这是在C code):

Suppose we have the following method (it is in c code):

const char *bitap_search(const char *text, const char *pattern)

我的问题是我怎么能比的文字和图案,如果他们是字符?这种方法就像一个子问题,但我很困惑,有点我可以写在字符等code术语? 如果(文[I] ==模式[I])? 看我很感兴趣,在这个算法中的java http://en.wikipedia.org/wiki/Bitap_algorithm 如何在Java中实现这一点?

My question is how can I compare text and pattern if they are char? This method is like a substring problem but I am confused a bit can I write in term of char such code? if (text[i]==pattern[i])? look i am interesting at this algorithm in java http://en.wikipedia.org/wiki/Bitap_algorithm how implement this in java?

R = malloc((k+1) * sizeof *R);

和请帮我翻译这code在java中   所以我们有两个文本字符串?  像我喜欢电脑是非常重要的   和行话字符串电脑是非常? 有谁能够给我解释一下我们所拥有的,而不是字符?

and please help me to translate this code in java so we have two string text? like "i like computer it is very important" and patter string " computer it is very"? can anybody explain me what we have instead of char?

推荐答案

我想你感到困惑的字符的区别和的char * 。在C语言中没有内置的字符串类型。字符串被重新psented为空值终止字符数组$ P $,这意味着字符串的最后一个字符必须是 \ 0 那么字符是一个字符,而的char * 是一个指向字符数组,我。即一个字符串。这意味着,这是完全正常的说如果(文[I] ==模式[I])

I think you are confused about the difference between char and char *. In C there is no built-in string type. Strings are represented as null-terminated character arrays, meaning that the last character of the string must be \0 So char is a single character, while char * is a pointer to an array of characters, i. e. a string. And that means that it is perfectly fine to say if (text[i] == pattern[i]).