Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Zadanie 1
- * Ten program rysuje twarze w ascii-art
- */
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct twarz twarz;
- struct twarz {
- char wlosy[6];
- char czolo[6];
- char oczy[6];
- char usta[6];
- char szyja[6];
- };
- void initialize (twarz* face) {
- int i;
- for (i=0; i<5; i++) {
- face->wlosy[i] = ' ';
- face->czolo[i] = ' ';
- face->oczy[i] = ' ';
- face->usta[i] = ' ';
- face->szyja[i] = ' ';
- }
- face->wlosy[5] = '\0';
- face->czolo[5] = '\0';
- face->oczy[5] = '\0';
- face->usta[5] = '\0';
- face->szyja[5] = '\0';
- face->czolo[0] = '/';
- face->czolo[1] = '"';
- face->czolo[2] = '"';
- face->czolo[3] = '"';
- face->czolo[4] = '\\';
- face->oczy[0] = '|';
- face->oczy[1] = 'o';
- face->oczy[3] = 'o';
- face->oczy[4] = '|';
- face->usta[0] = '\\';
- face->usta[2] = '-';
- face->usta[4] = '/';
- face->szyja[1] = '|';
- face->szyja[2] = '_';
- face->szyja[3] = '|';
- }
- void print_face (const twarz* face) {
- puts (face->wlosy);
- puts (face->czolo);
- puts (face->oczy);
- puts (face->usta);
- puts (face->szyja);
- puts ("");
- }
- void set_face_state (twarz* face, int state) {
- int i;
- for (i=0; i<5; i++)
- face->wlosy[i] = ' ';
- switch (state) {
- case 1:
- face->oczy[1] = 'o';
- face->oczy[3] = 'o';
- face->usta[2] = '-';
- break;
- case 2:
- face->oczy[1] = 'O';
- face->oczy[3] = 'O';
- face->usta[2] = 'U';
- break;
- case 3:
- face->oczy[1] = 'o';
- face->oczy[3] = 'o';
- face->usta[2] = '~';
- break;
- case 4:
- face->wlosy[1] = '\'';
- face->wlosy[2] = '.';
- face->wlosy[3] = '\'';
- face->oczy[1] = '@';
- face->oczy[3] = '@';
- face->usta[2] = '=';
- break;
- }
- }
- void read_state (int* state) {
- while (1) {
- puts ("Jaki stan studenta?");
- puts ("1. Normalny.");
- puts ("2. Szczesliwy.");
- puts ("3. Zakochany.");
- puts ("4. Normalny.");
- puts ("0. Zakoncz.");
- if (!( scanf ("%d", state) ) || !(0<=*state && *state<=4) ) {
- puts ("Podaj wlasciwy numerek!");
- continue;
- } else break;
- }
- }
- int main (void) {
- twarz face;
- int state=1;
- initialize (&face);
- while (1) {
- read_state (&state);
- if (state==0) break;
- set_face_state (&face, state);
- print_face (&face);
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment