我一直在读一些关于C的东西,我是初学者,此时我就在这里:
此功能保持键盘的输入:
void store_sequence(char *arg) {
strcpy(estado.seq, arg);
estado.tamanho = strlen(arg);
}
这就是我到目前为止检查键盘上是否有As的字符串:
void sequence_does_contain_As_and_Bs(char *arg) {
char buf [] = estado.seq;
s = strchr (buf, 'A');
if (s != NULL)
printf ("found a 'A' at %s\n", s);
}
所以,基本上,我需要检测输入字符串是否只有As和Bs
答案 0 :(得分:2)
看看这个 - http://www.cplusplus.com/reference/cstring/
特别是strspn()
和strcspn()
答案 1 :(得分:1)
试试这个:
char buf [] = estado.seq;
int len = estado.tamanho;
int i;
int contains = 1;
for (i = 0; i < len; ++i)
if (buf[i] != 'A' && buf[i] != 'B') {
contains = 0;
break;
}
if (contains)
// do whatever you want if the string contains only As and Bs