Politechnika Śląska - strona 149

Macros and strings

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 665

Macros and strings  Formal parameters are not replaced within quoted strings: #define M(iks) printf("iks=%d", iks); int v2=789; M(v2) /* the result: iks=789 */  If a parameter name is preceded by a # in the replacement text, the combina...

Other functions

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 567

Other functions  fabs(x) absolute value, |x|  ldexp(x,n) x*2 n  frexp(x, int *ip) splits x into a normalized fraction in the interval [1/2,1) which is returned, and a power of 2, which is stored in *ip . If x is zero, both parts of the result are zero.  modf(x, double *ip) splits x into integra...

Predefined macros variable argument lists

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 483

Predefined macros variable argument lists  Header file:  Macros: void va_start(va_list ap, lastfix); type va_arg(va_list ap, type); void va_end(va_list ap);  Type: va_list  Purpose - to provide a way for defining functions of unknown number of parameters  Idea - the function gets a

Random numbers

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 595

Random numbers  Generating true random numbers is a problem!  Usually computers use special functions, generating pseudo random numbers  The library stores information to be used in the next call to the generator int rand(void);  Returns successive pseudo-random numbers in the range from 0 to R...

SetPixel

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 679

SetPixel  The SetPixel function sets the pixel at the specified coordinates to the specified color. COLORREF SetPixel( HDC hdc , /* handle to device context */ int X , /* x-coordinate of pixel */ int Y , /* y-coordinate of pixel */ COLORREF crColor /* pixel color */ );  Parameters  hdc - Handle ...

Solution of Line buffered input

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 294

Solution  Simple method: read and dump all the characters from the input buffer until a '\n' after the scanf() call: void dump_line( FILE * fp ) { int ch; while( (ch = fgetc(fp)) != EOF && ch != '\n' ) /* null body */ ; } Modified code int x; char st[31];

Speed examples

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 553

Speed - examp les  Intel Celeron M 540 (1862MHz) 0.94 GFLOPs  Intel Pentium 4 (3055MHz) 0.73 GFLOPs  Intel Core 2 Duo E6300 (1870MHz) 1.8 GFLOPs  Intel Core 2 Duo E6600 (3700MHz) 3.4 GFLOPs ...

The function time

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 476

The function time time_t time(time_t *timer);  time gives the current time, in seconds, elapsed since 00:00:00 GMT, January 1, 1970  It stores that value in the location *timer, provided that timer is not a null pointer #include #include int m...

The Year 2038 Bug

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 497

The Year 2038 Bug  Tuesday, January 19, 2038, GMT 03:14:07  The counter will overflow and go to negative numbers  Proposed solution: use 64-bits numbers - moves the problem to Sunday, December 4 th , year 292 277 026 596 - would be a total solut...

Trigraph sequences

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 371

Trigraph sequences  The characters in C source: 7-bit ASCII  Some character sets don 't cover ASCII  For reduced sets: trigraph sequences  Replaced by the corresponding single character  Replacement occurs before any other processing ??= # ??( [ ?? } ??' ^ ??! | ??- ~  Replacement occurs befo...