Last change
on this file since a47fe52 was
a573c22,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
example programs updated for concurrency paper
|
-
Property mode set to
100644
|
File size:
890 bytes
|
Rev | Line | |
---|
[466fa01] | 1 | #include <stdio.h> |
---|
| 2 | |
---|
| 3 | typedef struct { |
---|
[a573c22] | 4 | int restart, g, b; |
---|
[466fa01] | 5 | char ch; |
---|
| 6 | } Fmt; |
---|
| 7 | |
---|
| 8 | void comain( Fmt * f ) { |
---|
[a573c22] | 9 | static void * states[] = {&&s0, &&s1}; |
---|
| 10 | goto *states[f->restart]; |
---|
| 11 | s0: f->restart = 1; |
---|
[466fa01] | 12 | for ( ;; ) { |
---|
| 13 | for ( f->g = 0; f->g < 5; f->g += 1 ) { // groups |
---|
| 14 | for ( f->b = 0; f->b < 4; f->b += 1 ) { // blocks |
---|
[a573c22] | 15 | do { |
---|
| 16 | return; s1: ; |
---|
| 17 | } while ( f->ch == '\n' ); // ignore |
---|
[466fa01] | 18 | printf( "%c", f->ch ); // print character |
---|
| 19 | } |
---|
| 20 | printf( " " ); // block separator |
---|
| 21 | } |
---|
| 22 | printf( "\n" ); // group separator |
---|
| 23 | } |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | int main() { |
---|
[a573c22] | 27 | Fmt fmt = { 0 }; |
---|
[466fa01] | 28 | comain( &fmt ); // prime |
---|
| 29 | for ( ;; ) { |
---|
| 30 | scanf( "%c", &fmt.ch ); // direct read into communication variable |
---|
| 31 | if ( feof( stdin ) ) break; |
---|
| 32 | comain( &fmt ); |
---|
| 33 | } |
---|
| 34 | if ( fmt.g != 0 || fmt.b != 0 ) printf( "\n" ); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | // Local Variables: // |
---|
| 38 | // tab-width: 4 // |
---|
| 39 | // compile-command: "gcc-8 Format.c" // |
---|
| 40 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.