Originally Posted by
Matticus
Code:
for(i=0;i<100;i++){
if((arr[i]== 'o'|| arr[i]=='O')&&(arr[i+1]=='h' ||arr[i+1]=='H'))
judge++;
}
Be careful - you're overrunning the bounds of your array here (i+1)
i changed the code
Code:
#include<stdio.h>
int main(){
char arr[100],OH[]={'O','o','H','h'};
int i,x=0;
printf("please input ");
scanf("%s",arr);
for(i = 0; i<100; i++){
int judge = 0;
int j;
for(j = 0; j < 3; j++)
if(arr[i] == OH[j])
judge = 1;
if(judge){
x++;
continue;}
}
if(x>0)
printf("OH");
else
printf("not OH");
return 0;
}
output OH with any input