Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

13. You always should try to make a good first impression.

Answered: 1 week ago