Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can some body tell me what is wrong with my first assert statement in my code below. It always shows failed when executed. I am

can some body tell me what is wrong with my first assert statement in my code below. It always shows failed when executed. I am just tired. I exactly want why it is failing. I am using gcc.

#include #include #include #include #include #include #include #include

int main(int argc, char** argv) { if(argc != 2) { assert(fprintf(stderr, "Incorrect number of arguments. ") == -1); } char * end; errno = 0; //long n = strtol(argv[1], &end, 10); long n = strtol(argv[1], &end, 10);

//Ensure proper argument is passed.(To check that argument works and is passed without error) if (argv[1] == end) printf (" number : %lu invalid (no digits found, 0 returned) ", n); else if (errno == ERANGE && n == LONG_MIN) printf (" number : %lu invalid (underflow occurred) ", n); else if (errno == ERANGE && n == LONG_MAX) printf (" number : %lu invalid (overflow occurred) ", n); else if (errno == EINVAL) /* not in all c99 implementations - gcc OK */ printf (" number : %lu invalid (base contains unsupported value) ", n); else if (errno != 0 && n == 0) printf (" number : %lu invalid (unspecified error occurred) ", n); else if (errno == 0 && argv[1] && *end != 0) printf (" number : %lu valid (but additional characters remain) ", n);

for(int i = 1; i <= n; i++) { assert(printf("Process: %i %i ", getpid(), i) >= 0); } //return 0; exit(n); }

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

Students also viewed these Databases questions