Guest User

Godzio

a guest
Oct 27th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. /*
  2.  * Zadanie 1
  3.  * Ten program rysuje twarze w ascii-art
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. typedef struct twarz twarz;
  10.  
  11. struct twarz {
  12.     char wlosy[6];
  13.     char czolo[6];
  14.     char oczy[6];
  15.     char usta[6];
  16.     char szyja[6];
  17. };
  18.  
  19. void initialize (twarz* face) {
  20.     int i;
  21.    
  22.     for (i=0; i<5; i++) {
  23.         face->wlosy[i] = ' ';
  24.         face->czolo[i] = ' ';
  25.         face->oczy[i] = ' ';
  26.         face->usta[i] = ' ';
  27.         face->szyja[i] = ' ';
  28.     }
  29.    
  30.     face->wlosy[5] = '\0';
  31.     face->czolo[5] = '\0';
  32.     face->oczy[5] = '\0';
  33.     face->usta[5] = '\0';
  34.     face->szyja[5] = '\0';
  35.    
  36.     face->czolo[0] = '/';
  37.     face->czolo[1] = '"';
  38.     face->czolo[2] = '"';
  39.     face->czolo[3] = '"';
  40.     face->czolo[4] = '\\';
  41.    
  42.     face->oczy[0] = '|';
  43.     face->oczy[1] = 'o';
  44.     face->oczy[3] = 'o';
  45.     face->oczy[4] = '|';
  46.    
  47.     face->usta[0] = '\\';
  48.     face->usta[2] = '-';
  49.     face->usta[4] = '/';
  50.    
  51.     face->szyja[1] = '|';
  52.     face->szyja[2] = '_';
  53.     face->szyja[3] = '|';
  54. }
  55.  
  56.  
  57. void print_face (const twarz* face) {
  58.     puts (face->wlosy);
  59.     puts (face->czolo);
  60.     puts (face->oczy);
  61.     puts (face->usta);
  62.     puts (face->szyja);
  63.     puts ("");
  64. }
  65.  
  66. void set_face_state (twarz* face, int state) {
  67.     int i;
  68.     for (i=0; i<5; i++)
  69.         face->wlosy[i] = ' ';
  70.    
  71.     switch (state) {
  72.         case 1:
  73.             face->oczy[1] = 'o';
  74.             face->oczy[3] = 'o';
  75.             face->usta[2] = '-';
  76.             break;
  77.            
  78.         case 2:
  79.             face->oczy[1] = 'O';
  80.             face->oczy[3] = 'O';
  81.             face->usta[2] = 'U';
  82.             break;
  83.            
  84.         case 3:
  85.             face->oczy[1] = 'o';
  86.             face->oczy[3] = 'o';
  87.             face->usta[2] = '~';
  88.             break;
  89.            
  90.         case 4:
  91.             face->wlosy[1] = '\'';
  92.             face->wlosy[2] = '.';
  93.             face->wlosy[3] = '\'';         
  94.             face->oczy[1] = '@';
  95.             face->oczy[3] = '@';
  96.             face->usta[2] = '=';
  97.             break;
  98.     }
  99. }
  100.  
  101. void read_state (int* state) {
  102.     while (1) {
  103.         puts ("Jaki stan studenta?");
  104.         puts ("1. Normalny.");
  105.         puts ("2. Szczesliwy.");
  106.         puts ("3. Zakochany.");
  107.         puts ("4. Normalny.");
  108.         puts ("0. Zakoncz.");
  109.         if (!( scanf ("%d", state) ) || !(0<=*state && *state<=4) ) {
  110.             puts ("Podaj wlasciwy numerek!");
  111.             continue;
  112.         } else break;
  113.     }
  114. }
  115.  
  116.  
  117. int main (void) {
  118.     twarz face;
  119.     int state=1;
  120.     initialize (&face);
  121.    
  122.     while (1) {
  123.         read_state (&state);
  124.         if (state==0) break;
  125.        
  126.         set_face_state (&face, state);
  127.         print_face (&face);
  128.     }
  129.    
  130.     return EXIT_SUCCESS;
  131. }
  132.  
  133.  
Advertisement
Add Comment
Please, Sign In to add comment