I've made a program that identifies and returns the highest streak of consecutive, repeating digits. When I run the program, I receive the error listed above. I'm not calling any recursive functions, just one function that analyzes the digits. The code is listed below. I'm not including the digits analyzed for obvious reasons, just know it is 10 million digits.
// pi.c
#include <stdio.h>
#define SIZE 10000000
unsigned int findDigits(const char pi[], char *mostRepeatingDigitPtr, unsigned int *repeatLocationPtr);
int main(void)
{
// 10 million digits of pi
const char pi[] = "INSERT 10 MILLION CHARACTERS";
unsigned short int repeatStreak;
char mostRepeatingDigit;
unsigned int repeatLocation;
// pass to findDigits()
repeatStreak = findDigits(pi, &mostRepeatingDigit, &repeatLocation);
printf("The largest amount of repeating digits was: %hu. The repeated digit was: %c. The position on the array was %u.", repeatStreak, mostRepeatingDigit, repeatLocation);
return 0;
}
unsigned int findDigits(const char pi[], char *mostRepeatingDigitPtr, unsigned int *repeatLocationPtr)
{
char lastDigit = '3';
unsigned short int repeatStreak = 0;
unsigned short int highestRepeat = 0;
unsigned int repeatLocation = 0;
// loop through 10 million digits
for (unsigned int i = 0; i < SIZE; ++i) {
if (pi[i] == lastDigit) {
++repeatStreak;
repeatLocation = i - 1;
}
else {
if (repeatStreak > highestRepeat) {
highestRepeat = repeatStreak;
*mostRepeatingDigitPtr = lastDigit;
*repeatLocationPtr = i - repeatStreak;
}
lastDigit = pi[i];
repeatStreak = 0;
}
}
// return highest streak
return highestRepeat + 1;
}
Thanks in advance.