Politechnika Śląska - strona 300

note /search

Avoiding goto - omówienie zagadnienia

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

Avoiding goto • Code involving a goto can always be written without one, which may require more coding (additional variables and tests): found = 0; for (i = 0; i ...

Calling a function - examples

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

Calling a function /* test the power function */ int main() { int i; for (i = 0; i (…) … Calling a function /* test the power function */ int main() { int i; for (i = 0; i < 10; i++) printf("%d %d %d\n", i, power(2,i), power(-3,i));...

Character Output - examples

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

Character Output • Writing a single character or EOF: int putc(int c, FILE *stream); • Example: putc('A',stdout); • Writing a single character to stdout : int putchar(int c); • putchar('A') wor...

Clearerr - examples

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

Clearerr Resets the error indicator for a stream void clearerr( FILE * stream ); • resets the error indicator and end-of-file indicator for stream • Error indicators are not automatically cleared • Once the error indicator for a specified stream is set, operations on that stream continue to return ...

Closing a file - examples

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

Closing a file • The function int fclose(FILE *fp) - inverse of fopen • Most operating systems have some limit on the number of simultaneously opened - free the file pointers when they are no longer needed • fclose on an output file flushes the buffer • fclose is called automatically for each open ...

Command line arguments

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

Command line arguments • A program may be called from a command line • It may accept arguments (parameters) • When main is called, it is called with (at least) two arguments: - the number of arguments, including the program name itself; usually ca...

Conditions in C - examples

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

Conditions in C • There is no special type for logical values - other languages have boolean, bool etc. • Instead, integers are used: - 0 means false - any other value means true • Condition expressions return 0 or 1 • Condition expressions may...

Creating a list - examples

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

Creating a list struct stag *head, *p; /* two poi nters */ head = /* try to allocate memory for an element */ (struct stag*)malloc(sizeof(struct stag)); if (!head) exit(1); /* out of memory? */ head-x = 12.0; /* fill the element with data */ head-n...

Defining names - examples

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

Defining names #define name replacement list • Any occurrence of name , not in quotes and not part of another name, will be replaced by the replacement text • The name has the same form of an identifier • The replacement text can be any sequence of characters (not limited to numbers) ...

External variables - examples

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

External variables • An external variable must be defined , exactly once, outside of any function. This allocates memory for the variable. • The variable must also be declared in each function that wants to access it. This tells the type of the variable. • The declaration may be - an