I first initialize 0 to counter[10], and it is OK. However, somewhere I want to re-initialize with 0 again but fail.
The error message is
[Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11
#include <stdio.h>
#include <stdbool.h>
int main(void) {
int digit, counter[10] = {0}; //Declare variable "digit" to store individual number to be compared and declare an array for the input numbers
bool rep_digits; //Declare a boolean variable to determine whether the input numbers has repetitive numbers or none
int n; //Declare variable "n" to store the input numbers
while (true) { //This while loop serves as a loop for the user input
printf("\nEnter a number (capped at on this compiler): ");
scanf("%d", &n);
if (n == 0) { //The user input loop terminates when the user input a 0
break;
}
printf("Repeated digits(s): \n");
while (n > 0) { //If the condition is true, execute the arguments inside
digit = n % 10; //Obtain the remainder of the input number
counter[digit]++; //Increase the counter for the obtained remainder in the array
if (counter[digit] == 2) { //If the counter of that particular remainder is equal (and only equal) to 2, print out the number
printf("%2d\n", digit);
rep_digits = true; //Set the boolean variable to true if there is a repetitive number in the input
}
n /= 10; //Divide the input number by 10 to determine the next number either repetitive or not
}
counter[10] = {0}; // re-initialize to 0
if (rep_digits == false) { //If the boolean variable stays false then display this message
printf("No repeated digits\n");
}
}
return 0;
}