Стили и методы программирования




Пример 10.2.3


#include

#include

#include

char symbol;

int cnt;

enum States { St1, St2, St3, Exit } State;

inline States f_St1 ()

{

if ('a'<=symbol && symbol <= 'z')

printf ("%c", symbol);

cnt = 1;

symbol = getchar (); return St2;

}

else if (symbol != '\n') {

symbol = getchar (); return

}

else {symbol = getchar (); return

}

inline States f_St2 ()

{

if ('a'<=symbol && symbol <= 'z')

printf ("%c", symbol);

cnt++;

symbol = getchar (); return St2;

}

else if (symbol != '\n') {

printf (" -%i\n", cnt);

symbol = getchar (); return St1;

}

else {

printf (" - %i\n", cnt);

symbol = getchar (); return St3;

}

}

inline States f_St3 ()

{

if ('a'<=symbol && symbol <= 'z') {

printf ("%c", symbol);

cnt = 1;

symbol = getchar (); return St2;

}

else if (symbol != '\n') {

symbol = getchar (); return St1;

}

else return Exit;

}

void main( void )

{

symbol = getchar ();

State = St1;

for (;;)

{ switch ( State ) {

case St1: State = f_St1 ();

break;

case St2: State = f_St2 ();

break;

case St3: State = f_St3 ();

break;

default: return;

}

}

}




Содержание  Назад  Вперед