Fundamentals of Computer Programming - strona 11

note /search

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

Feof - examples

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

Feof #include int main(void) { FILE *stream; /* open a file for reading */ stream = fopen("TEST.TXT", "r"); /* read a character from the file */ fgetc(stream); /* check for EOF */ if (feof(stream)) printf("We have reached ...

Fflush - examples

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

Fflush Flushes a stream int fflush( FILE * stream ); • the file associated with stream should be opened for output • fflush writes to that file the contents of the buffer associated with the stream • If the stream is open for input, fflush clears the contents of the buffer (warnings) ...

File access - examples

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

File access • All examples so far have read from the standard input and written to the standard output • How to write a program that accesses a file that is not already connected to the program… • Use one of two groups of functions: - Buffered inpu...

File copyig 2nd

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

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

Formatted output the printf function

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

Formatted output the printf function • printf is capable of printing values of different types (texts, integers, floating point numbers and other). int x; x = 5; printf(”example: %d+1=%d\ n”,x,x+1); ...

Fseek - examples

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

Fseek Moves the file pointer to a specified location. int fseek( FILE * stream , long offset , int origin ); • moves the file pointer to a new location that is offset bytes from origin • The next ...

Functions - examples

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

Functions • Humans are capable of analysing about 7 items at the same time • What if a program is longer than 7 lines? • Decompose it into functions! - Write a few lines of code and assign them a name - Call them using the name • Of course, that is not the only reason for using functions... ...