Politechnika Śląska - strona 301

Feof - examples

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 490

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... ...

Goto and labels - overview

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

goto and labels • C provides a goto statement, and labels to jump to • The goto statement is never necessary • In practice it is easy to write code without it • Sometimes goto may be useful: breaking processing in some deeply nested structure: for ( ... ) for ( ... ) { ... if (error_occured) goto e...

Initialization of character arrays

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

Initialization of character arrays • A special case: charac ter arrays • A string may be used: char mystr[] = "hello"; is equivalent to : char mystr[] = { 'h', 'e', 'l', 'l', 'o', '\0' }; • In this case, the array size is six (five characters plus the terminating ' \0 ' ) ...

Input and output streams

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

Input and output streams short preview • Standard input: stdin • Standard output: stdout • Std. error stream: stderr • Details to be explained later • Normally these streams are associated with console: - stdin with the keyboard - stdout and stder...