the value of length is seven, word in file is hello, chosen_letter can be any that user guesses. chosen_letter is char ofcourse.
my problem is when we type in character 'l' for chosen_letter and it only counts it once. also, the if-loop in the second while loop doesnt work. please help, my assignment is due tommorow :/
void check_letter(char chosen_letter, FILE *ip_file, int length){
int count_let[20], i=0, x=0;
length = length-2;
while((d1[i] = fgetc(ip_file)) != EOF ){
printf("%c %d\n", d1[i], i);
if(d1[i] == chosen_letter){
printf("* %d\n", length);
count_let[x] = count_let[x] + i; /* records i in count_let[x] */
x++;
}
i++;
}
printf("%d, %d \n", x, length);
while(length >= 0){
if(length == count_let[x]){
printf("%c", chosen_letter);
} /* checks if length value equals count_let[x] value, if so prints the character. */
else printf("*"); /* checks if length value not equals count_let[x] value, if so prints '*' */
length--;
x--;
}
}