1 / 6

DASL 130 – C Programming Course

DASL 130 – C Programming Course. Lecture 6. Common Libraries. stdbool.h Provides: true constant = 1 false constant = 0 bool type Use with logical operators. Random Numbers. Random numbers are pseudorandom - there is always an algorithm behind the generation

Download Presentation

DASL 130 – C Programming Course

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DASL 130 – C Programming Course Lecture 6

  2. Common Libraries stdbool.h Provides: • true constant = 1 • false constant = 0 • bool type • Use with logical operators

  3. Random Numbers • Random numbers are pseudorandom - there is always an algorithm behind the generation • #include <stdlib.h> (gives you the rand() and srand() functions) • #include <time.h> (gives you the time() function)

  4. Random Numbers • srand( int ) ○ set the seed – number used as basis for sequence of random numbers ○ same seed = same sequence of numbers ○ default seed is ‘1’ For more random randomness set the seed by: • srand( time(NULL) ) rand() returns in the range from 0 to RAND_MAX

  5. Making A Library - Header Header File (filename.h) • Start with: #ifndef _ID_ #define _ID_ • Add prototypes for all functions in filename.c • If you have type definitions put them in the header • End with #endif

  6. Making A Library - Source Source File (filename.c) • Start with: #ifndef _ID_ #define _ID_ • Add all function definitions (not prototypes) to the middle • End with #endif

More Related