Fundamentals of Computer Programming - strona 12

note /search

Goto and labels - overview

  • Politechnika Śląska
  • 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
  • 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
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 504

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

Inserting elements - overview

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

inserting elements void insert(double a, struct stag **h) { struct stag *p; p = (struct stag*)malloc(sizeof(struct stag)); if (!p) exit(1); p-x = a; p-next = *h; *h = p; } head = NULL; insert(45.6, &head); insert(54.3, &head); insert(1234, &head); ...

Modifications of list - overview

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

Modifications • Appending at the en d requires a pointer to the last element - store a pointer to the tail of the list • Walking through elements is possible in only one direction - store pointers to the previous element in each element, creating ...

Nesting unions and structures

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

Nesting unions and structures • Unions may be defined in struc tures and arrays, and vice versa • Syntax for accessing elements: like structures • Example: struct { char *name; int flags; int utype; union { int i; float f; char *s; } u; } symtab[N...

Other functions operating on files

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

Other functions operating on files • feof Tests for end-of-file on a stream int feof( FILE * stream ); • returns a nonzero value after the first read operation that attempts to read past the end of the file • It returns 0 if the current position is not end of file • There is no error return ...

Other operations on lists

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

Other operations on lists • Looking for an element • Appending an element after the last element of the list • Inserting an element at a given position • Removing an element • Ch anging the order of elements • Insert an element at a known position:...

Parts of a C program

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

Parts of a C program • A C program, whatever its size, consis ts of functions and variables • A function contains statements that specify the computing operations to be done • Variables store values used during the computation ...

Passing arrays to functions

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

Passing arrays to functions • When the name of an array is used as an argument, the value passed to the function is the location or address of the beginning of the array • There is no copying of array elements! • More details on passing parameters to functions: later ...