this is from an personal online coursethis code is able to run on my mac but not on windows , any help would be nice:)finding number of palindrome , palindrome length , median digit distance each palindrome
#include <stdio.h>void quicksort(int array[], int lower, int upper);float median(int array[], int length);/* Compile with: gcc -std=c17 -pedantic -Werror ece2071_asg1.c -o ece2071_asg1 -lm*/int main(void){ int c; unsigned int count = 0; int length = 5000000; //Change 28664 to 5000000 static int array_1[5000000]; //Change 28664 to 5000000 /* Do NOT change the filename! Otherwise your assignment will fail. */ FILE* file = fopen("pi_5m.txt", "r"); if (file == 0) { printf("I can't open the file for reading.\n"); return -1; } while ((c = fgetc(file)) != EOF) { /* Your palindrome number hunting routines could start here */ if (c == '.') { continue; } c -= 48; //Convert ASCII to integer array_1[count] = c; //Putting all integers into array count++; } printf("The file is %d characters long.\n \n", count); fclose(file); int condition = 0; int palindromeLength = 2; // Printing Header printf("Palindrome Number of Median Digit"); printf("\n"); printf("Length Palindromes Distance"); printf("\n"); printf("---------- ----------- ------------"); printf("\n"); // Loop stop when number of palindrome of N palindrome length is 0 while (condition != 1) { int numberPalindrome = 0; int lowerBound = 0; int upperBound = 0; int digitDistance = 0; static int arrayDigitDistance[510000] = { 0 }; //Change 28664 to 510000 int indexDigitDistance = 0; //Get digits set by set for (int check = 0; check < (length - palindromeLength + 1); check++) { // Number of comparison need to do for each set of digits int numberComparison = palindromeLength / 2; // Count number of correct pairs in each set of digits int countComparison = 0; //Checking pairs in the set of digits for (int i = check, j = check + palindromeLength - 1, compare = 0; compare < numberComparison; i++, j--, compare++) { // Counting correct pairs if (array_1[i] == array_1[j]) { countComparison++; } else { break; } } // It is a palindrome if all pairs in a set is correct if (countComparison == numberComparison) { numberPalindrome++; // Store index number if (numberPalindrome == 1) { lowerBound = check; } else { upperBound = check; digitDistance = upperBound - lowerBound - 1; lowerBound = upperBound; arrayDigitDistance[indexDigitDistance] = digitDistance; indexDigitDistance++; } } } // Sorting quicksort(arrayDigitDistance, 0, indexDigitDistance - 1); // Finding median if (indexDigitDistance < 1) { printf("%10d %11d %12s\n", palindromeLength, numberPalindrome, "-"); } else { float mid = median(arrayDigitDistance, indexDigitDistance); printf("%10d %11d %12.1f\n", palindromeLength, numberPalindrome, mid); } palindromeLength++; if (numberPalindrome == 0) { condition = 1; } } printf("\n"); return 0;}void quicksort(int array[], int lower, int upper){ if (lower < upper) { // Pivot index int p = lower; // Counter from left int i = lower + 1; //Counter from right int j = upper; while (i < j) { while (array[p] >= array[i] && i < j) { i++; } while (array[p] < array[j]) { j--; } if (i < j) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } } if (array[p] > array[j]) { int temp = array[p]; array[p] = array[j]; array[j] = temp; } // Sorting sub-array quicksort(array, lower, j - 1); quicksort(array, j + 1, upper); }}// Finding medianfloat median(int array[], int length) { float mid = 0; if (length % 2 == 0) { mid = (float)(array[length / 2] + array[(length / 2) - 1]) / 2; } else { mid = array[(length + 1) / 2 - 1]; } return mid;}
desire outputpalindrome number of median digitlength palindromes distance
2 499659 6.0 3 500795 6.0 4 50030 68.0 5 50169 68.0 6 5018 692.0 7 4915 732.5 8 547 6852.0 9 501 6727.5 10 42 100312.0 11 44 67831.0 12 4 1447397.0 13 2 843446.0 14 0 -