Please do include both files main and header as stated in t

Please do include both files ( main, and header) as stated in the question using c programming :)

Name the files, bonus.c and bonus.h char highestFreq(char *str) - this function should return the highest frequency character c in the string. For example, a call to this function with the string \"Hello World\", would return \"1\",

Solution

// bonus.h

#include <string.h>
#ifndef BONUS_H
#define BONUS_H

char highestFreq(char *str)
{
   int stringlength = strlen(str);
   char result[100];
   int times[100] = {0}, f = 0;
   int i, j = 0, k, maximum = 1, index = 0;

   for (i = 0; i < stringlength; i++)
   {

   if (i == 0)
   {
   result[j++] = str[i];
   times[j - 1]++;
   }
   else
   {
   for (k = 0; k < j; k++)
   {
   if (str[i] == result[k])
   {
   times[k]++;
   f = 1;
   }
   }
   if (f == 0)
   {
   result[j++] = str[i];
   times[j - 1]++;
   }
   f = 0;
   }
   }

   for (i = 0; i < j; i++)
   {
   if ((i == 0) && (result[i] != \' \'))
   {
   maximum = times[i];
   continue;
   }
   if ((maximum < times[i]) && (result[i] != \' \'))
   {
   maximum = times[i];
   index = i;
   }
   }

   return result[index];
}

#endif

//bonus.c
// C code determine highest frequency character in string

#include <stdio.h>
#include <string.h>
#include \"bonus.h\"


int main()
{
char str[100];

printf(\"Enter string: \");
scanf(\"%[^\ ]s\", str);

char c = highestFreq(str);

printf(\"\ Highest Frequency Character: %c\ \", c);

return 0;
}

/*
output:

Enter string: Hello World

Highest Frequency Character: l

*/

Please do include both files ( main, and header) as stated in the question using c programming :) Name the files, bonus.c and bonus.h char highestFreq(char *str
Please do include both files ( main, and header) as stated in the question using c programming :) Name the files, bonus.c and bonus.h char highestFreq(char *str

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site