我想写的思路:
if(for(int i=0;i<10;i++){
s[i] != c;
}){
printf("Not found!");
}
但这样是运行不了的。
我想要达到的结果:如果c不在s[10]中,printf("Not found!");
代码,望采纳,谢谢:
#include<stdio.h>
int main() {
char s[10] = "qwefgdyts";
int h = 0;
for (int i = 0; i < 10; i++) {
if (s[i] == 'c') {
printf("found c");
h = 1;
}
}
if (h == 0) {
printf("not found c");
}
return 0;
}
效果:
for(i;i<10;i++)
{
if(s[i]!=c)
{
printf("Not fouond!\n");
}
#include<stdio.h>
int main(){
char s[]="helloworld";
char c='a';
int flag=0;
for(int i=0;i<10;i++){
if(c==s[i]){
flag=1;
break;
}
}
if(flag==1){
printf("found!");
}else{
printf("Not found!");
}
return 0;
}