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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!