I am preapring for a test in programing and one of the tasks is making a program that will cout how many words start and end with the same latter and also subtract number of upper case latters with the number of numerical cacters. It must be done in a separate function and it must return two values. I know i am not the best at this but i think my code should work and for some reason it brakes at the while loop. What am I doing wrong?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void calculation(char string[], int *n_words, int *n_numbers, int *n_uppercase) {
char first_letter = ' ', last_letter = ' ';
*n_words = 0;
*n_numbers = 0;
*n_uppercase = 0;
for (int i = 0; i < strlen(string); i++) {
first_letter = string[i];
last_letter = string[i];
while(last_letter != ' ')
{
if (isdigit(string[i])) (*n_numbers)++;
else if (isupper(string[i])) (*n_uppercase)++;
last_letter = string[i];
i++;
}
if (last_letter == first_letter) (*n_words)++;
}
}
int main() {
char tekst[169];
int n_numbers, n_uppercase, n_words;
printf("Write a text: \n");
gets_s(tekst);
calculation(tekst, &n_words, &n_numbers, &n_uppercase);
printf("Number of words with the same starting and ending letter: % d \n", n_words);
printf("number of upper case characters - number of numbers :%d \n ", n_uppercase - n_numbers);
}
The program should proerly output number of words that have same starting and endig characters but insted of that it just gives me an error box with error
Expression: c -I c 255 and exit code 3