3
I would like to separate a word and compare each element of the string with a letter, I tried to make this comparison using the strcmp()
but when executed seems to ignore it, or does not perform.
When I remove the condition the function separates the word normally but I cannot store the letter or compare it.
#include <string.h>
#include <stdio.h>
int main() {
char str[20];
gets(str);
int i;
int strLength = strlen(str);
for (i = 0; i < strLength; i++) {
if (strcmp(str[i],"c") == 0)
{
printf("Achei");
}
printf("[%c]", str[i]);
}
}
If you want to compare a certain position of your string with a character use:
if (str[i] == 'c')
 {
 printf("Achei");
 }
– anonimo