Guest User

Untitled

a guest
Sep 19th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1.  
  2. // Online C Compiler - Build, Compile and Run your C programs online in your favorite browser
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. struct display {
  8. int data_pin;
  9. int lacth_pin;
  10. int clock_pin;
  11.  
  12. int indicators_num;
  13. int first_cathode_pin;
  14. int* indicator_state;
  15.  
  16. };
  17.  
  18. struct display displayCreate(int data_pin, int lacth_pin, int clock_pin, int indicators_num, int first_cathode_pin) {
  19.  
  20. int* indicator_state = malloc( sizeof(int) * indicators_num );
  21.  
  22. struct display main_display = {data_pin, lacth_pin, clock_pin, indicators_num, first_cathode_pin, indicator_state};
  23.  
  24. for(int i = 0; i < indicators_num; i++) {
  25. main_display.indicator_state[i] = 0;
  26. }
  27.  
  28. return main_display;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. struct display main_display = displayCreate(2,3,4,4,5);
  35. main_display.indicator_state[1] = 22;
  36.  
  37. for(int i = 0; i < main_display.indicators_num; i++) {
  38. printf( "indicator %d = %d\n", i, main_display.indicator_state[i] );
  39. }
  40.  
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment