Advertisement
cd62131

Light Turn

Dec 19th, 2013
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef enum{
  5.     off, on
  6. } binary;
  7.  
  8. typedef struct{
  9.     binary denki;
  10. } heya;
  11.  
  12. void turn(heya *s) {
  13.     if (s->denki == off) s->denki = on;
  14.     else s->denki = off;
  15. }
  16.  
  17. void suitti(heya *sinsitu)
  18. {
  19.     if (sinsitu->denki == on) {
  20.         printf("点灯\n");
  21.         turn(sinsitu);
  22.     } else {
  23.         printf("消灯\n");
  24.         turn(sinsitu);
  25.     }
  26. }
  27.  
  28. int main()
  29. {
  30.     heya *sinsitu;
  31.     sinsitu = (heya *) malloc(sizeof(heya));
  32.     sinsitu->denki = on;
  33.  
  34.     suitti(sinsitu);
  35.     suitti(sinsitu);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement