This blog is under construction

Saturday 5 May 2012

assert

Header file:
    assert.h

Synopsis:
     void assert(int expr);

Description:
     It aborts the program if the expr is false.




Sample program for assert in C:



  #include<stdio.h>
  #include<assert.h>
  #include<errno.h>
  int main() {
        FILE *fp;
        fp = fopen("jp.txt", "r");
        if (fp == NULL) {
                assert(fp);
        }

        printf("File opened in read mode\n");
        fclose(fp);
        return 0;
  }




  Output:
  jp@jp-VirtualBox:~/cpgms/assert$ ./a.out
  a.out: assert.c:8: main: Assertion `fp' failed.
  Aborted
  jp@jp-VirtualBox:~/cpgms/assert$ ls
  a.out  assert.c



2 comments:

  1. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

    Data Science Interview Questions

    ReplyDelete
  2. Do you need Finance? Are you looking for Finance? Are you looking for finance to enlarge your business? We help individuals and companies to obtain finance for business expanding and to setup a new business ranging any amount. Get finance at affordable interest rate of 3%, Do you need this finance for business and to clear your bills? Then send us an email now for more information contact us now via (financialserviceoffer876@gmail.com) whats-App +918929509036 Dr James Eric Finance Pvt Ltd Thanks

    ReplyDelete