Question
I don't understand why my code is not reading my bool array as false as I declared. I have a for loop to make it
I don't understand why my code is not reading my bool array as false as I declared.
I have a for loop to make it true, but even without running the loop, it is printing everything as true.
#include #include #include
#define MAX_NUM 100 #define FLUSH stdin=freopen(NULL,"r",stdin)
char n[MAX_NUM] = {0};
int main() {
int i, j, l; bool x[MAX_NUM + 1] = {false};
do { printf("Input a number (1-100): "); fgets(n, MAX_NUM, stdin); FLUSH; l = strtol(n, NULL, 10);
if (l < 1 || l > MAX_NUM) { printf("Incorrect input. Please try again! "); } } while (l < 1 || l > MAX_NUM);
for (i = 1; i <= l; i++) { x[i] = true; }
printf("Items that are true: "); for (i = 1; i <= l; i++) { if (i < l) { printf("%d, ", i); } else { printf("%d.", i); }
} return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started