Fundamentals of Computer Programming - strona 7

note /search

Memcpy

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

Memcpy  void *memcpy (void *dest, const void *src, size_t n);  Copies a block of n bytes from src to dest  If src and dest overlap, the behavior is Undefined #include #include int main() { char src[] = ""; char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709"; char *ptr;

Memmove

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

Memmove  void *memmove(void *dest, const void *src, size_t n);  Copies a block of n bytes from src to dest  Even when the src and dest blocks overlap, bytes in the overlapping locations are copied correctly #include #include int main() { char dest[] = "abcdefghijklmnopqrstuvwxyz0123456789...

Arithmetic operators

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

Arithmetic operators • +, -, *, /, % • Example: a year is a leap year if it is divisible by 4 but not by 100, except that years divisible by 400 are leap years. if ((year%4 == 0 && year%100 != 0) || year%400 == 0)

Assignment operators op

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

Assignment operators op = • If expr 1 and expr 2 are expressions, then expr 1 op= expr 2 is equivalent to expr 1 = ( expr 1 ) op ( expr 2 ) except that expr 1 is computed only once. • op may be one of: + - * / % & ^ | • Examples: ...works like: x += 10; x = x+10; a *= b + c; a = a*(b+c); ...

Buffering - examples

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

Buffering • The hard drive is not capable of reading/writing sinlge bytes • The smallest amount is usually 512 bytes (a sector) • What happens if your program writes single bytes? • When using buffered i/o, they are buffered - A buffer is filled without writing data to HDD - When the buffer is full...

Character Input - examples

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

Character Input • Reading a single character or EOF: int getc(FILE *stream); the above is called a prototype • Example: int c; c = getc(stdin); • Why to use int for c instead of char? • Reading...

Conditions - examples

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

Conditions - examples • if (ab) printf(”yes!\n”); • if (ab && bc) ... • if (2+a == 3*b) ... • if ((a4) == (b9 && an++) ... /* will n be incremented? */ ...

Echo - examples

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

Echo #include /* echo command-line argument s; 1st version (K&R) */ int main(int argc, char *argv[]) { int i; for (i = 1; i /* echo command-line arguments; 2nd version (K&R) */ int main(int argc, char *argv[]) { while (--argc 0) printf(&...

File copying

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

File copying #include /* copy input to output; 1st version */ int main() { int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); } return 0; } ...

Fill the table at run time

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

fill the table at run time char *name[4]; /* an array of 4 pointers to characters */ name[0] = (char*) malloc(strlen("Illegal month")+1); if (name[0]==NULL) fprintf(stderr,"Out of memory\n"); else strcpy(name[0],"Invalid mo...