【发布时间】:2017-03-02 17:40:51
【问题描述】:
我有一个关于字符串数组的问题。
我正在尝试寻找一种方法来检查字符串中是否包含不需要的字符。
测试数组必须只包含以下 8 个选项之一:{'A','a','C','c','G','g','T','t'}
在此检查过程之前删除所有空格。
如果我有两个数组 A = {AGctcgtacgtacg} B = {CGTAagctFcg}
A 应该通过测试,B 应该失败,因为其中包含“F”。
我正在考虑使用 for 循环遍历数组的每个元素并尝试检查字符是否是选项之一。
const char test[] = {'A','a','C','c','G','g','T','t'};
int l = strlen(A);
char A[] = {AGctcgtacgtacg}
char B[] = {CGTAagctFcg}
for (i = 0; i < l; i++){
if (A[i] is one of the characters in test){
do nothing... (keep checking)
}
else{
break;
printf("Error: the array contains unwanted character.");
exit(1);
}
}
【问题讨论】: