Shortly after you told me that I managed to do it, I looked online how someone else did the average and saw he did something similar to what I tried but the only thing was I wrote float where I shouldn´t so it didn´t work.
But anyways here it is
Code:
#include <stdio.h>
#include <string.h>
float my_compare(char str1[], char str2[], int indexStart, int indexEnd);
int main()
{
char str1[50];
char str2[50];
int a;
int b;
printf("\nEnter the first string:");
fgets(str1,50,stdin);
printf("\nEnter the second string:");
fgets(str2,50,stdin);
do{
printf("\n(Start index can’t be bigger then the end index.)\nPlease enter the start index: ");
scanf("%d",&a);
printf("Please enter the end index: ");
scanf("%d",&b);
} while (b<a);
int c = my_compare(str1, str2, a, b);
}
float my_compare(char str1[], char str2[], int indexStart, int indexEnd)
{
float sum = 0;
float e = 0;
float avrage = 0;
for(int i=indexStart; i<indexEnd; ++i) //this is the substring for both str1 and str2
{
if(str1[i]==str2[i]) //only the same characters
{
printf("\n %4c --> %4d\n ", str1[i], str1[i]);
sum += str1[i];
++e;
}
}
avrage = sum/e;
printf("The average ASCII sum of the compared strings is: %f\n",avrage);
}
Thank you for helping me