How to Split a Word into letters

char letters[20][2];
char input[20];
gets(input);

My input is "binary"
then I want to have
b >> letters[0]
i >> letters[1]
n >> letters[2]
a >> letters[3]
r >> letters[4]
y >> letters[5]

then I will check if "i", letter[1] is same
program will print "The word is same"
Last edited on
The word is in an array. It is already split into letters. If you look at input[0], for example, it will be a 'b'.
I
try use strcmp(letters[1], 'i') >> error
try use strcmp(letters[1], "i") >> error
try use letters[i] = 'i' >> error

but if I use printf("%c", letters[1])
output is "i"

strcmp does not compare characters. It compares strings. You can just do:

if (input[1] == 'i')...
Last edited on
const char VOCAL[5][2] = {"a", "i", "u", "e", "o"};
if(strcmp(input[1], VOKAL[1]) == 0)
printf("The word is same");
ERROR
if(input[1] == vokal[1])
printf("The word is same");
ERROR TOO
Please help me
Last edited on
Thx, this problem solved
with const char VOKAL[5] = {'a', 'i', 'u', 'e', 'o'};
In both cases you are comparing a character to a C string. You need to compare like types.

Either make VOCAL an array of characters rather than an array of strings, or compare to the first character in each string: if(input[1] == VOCAL[1][0])

edit: Too late. Looks like you figured it out on your own. Congrats!
Last edited on
Topic archived. No new replies allowed.