Fundamentals of Computer Programming - strona 5

note /search

Low Level IO

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 567

Low Level I/O - Read and Write int n_read = read(int fd, char *buf, int n); int n_written = write(int fd, char *buf, int n);  Each call returns a count of the number of bytes transferred  On reading, the number of bytes returned may be less than the number requested  A return value of zero bytes...

Macro substitution

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 567

Macro substitu tion  A definition has the form #define name replacement_text  Subsequent occurrences of the token name will be replaced by the replacement_text  The name in a #define has the same form as a variable name  The replacement text is arbitrary  The replacement text is the rest of th...

Macros and strings

  • Politechnika Śląska
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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...