#include <stdio.h>
#include <math.h>
#define MAX 100
int str_length(char str[]) {
int i =0;
while(str[i]!='\0') {
i++;
}
return i;
}
int str_chave(char str[], int comp) {
int i=0;
char chave;
printf("Informe um caractere: ");
for (; i < comp; i++) {
if(str[i]==chave) {
return 1;
}
}
return 0;
}
int main() {
char string[MAX];
int comp,chave;
printf("Digite uma string: ");
comp = str_length(string);
printf("Comprimento de '%s': %d\n",string
,comp
);
chave=str_chave(string,comp);
if(chave==0)
printf("O caractere informado nao existe na string.\n"); else
printf("O caractere informado existe na string.\n");
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CiNkZWZpbmUgTUFYIDEwMAoKaW50IHN0cl9sZW5ndGgoY2hhciBzdHJbXSkgewogICAgaW50IGkgPTA7CgogICAgd2hpbGUoc3RyW2ldIT0nXDAnKSB7CiAgICAgICAgaSsrOwogICAgfQoKICAgIHJldHVybiBpOwp9CgppbnQgc3RyX2NoYXZlKGNoYXIgc3RyW10sIGludCBjb21wKSB7CiAgICBpbnQgaT0wOwogICAgY2hhciBjaGF2ZTsKCiAgICBwcmludGYoIkluZm9ybWUgdW0gY2FyYWN0ZXJlOiAiKTsKICAgIHNjYW5mKCIgJWMiLCZjaGF2ZSk7CgogICAgZm9yICg7IGkgPCBjb21wOyBpKyspIHsKICAgICAgICBpZihzdHJbaV09PWNoYXZlKSB7CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9CgppbnQgbWFpbigpIHsKICAgIGNoYXIgc3RyaW5nW01BWF07CiAgICBpbnQgY29tcCxjaGF2ZTsKCiAgICBwcmludGYoIkRpZ2l0ZSB1bWEgc3RyaW5nOiAiKTsKICAgIHNjYW5mKCIlW15cbl1zIixzdHJpbmcpOwoKICAgIGNvbXAgPSBzdHJfbGVuZ3RoKHN0cmluZyk7CgogICAgcHJpbnRmKCJDb21wcmltZW50byBkZSAnJXMnOiAlZFxuIixzdHJpbmcsY29tcCk7CgogICAgY2hhdmU9c3RyX2NoYXZlKHN0cmluZyxjb21wKTsKICAgIGlmKGNoYXZlPT0wKQogICAgICAgIHByaW50ZigiTyBjYXJhY3RlcmUgaW5mb3JtYWRvIG5hbyBleGlzdGUgbmEgc3RyaW5nLlxuIik7CiAgICBlbHNlCiAgICAgICAgcHJpbnRmKCJPIGNhcmFjdGVyZSBpbmZvcm1hZG8gZXhpc3RlIG5hIHN0cmluZy5cbiIpOwoKICAgIHJldHVybiAwOwp9Cg==