fork download
  1. #include <stdio.h>
  2.  
  3. #define WIDTH 40
  4. #define HEIGHT 20
  5.  
  6. void putpixel(char screen[HEIGHT][WIDTH], int x, int y, char c) {
  7. if(x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT)
  8. screen[y][x] = c;
  9. }
  10.  
  11. int main() {
  12. char screen[HEIGHT][WIDTH];
  13. // Initialize screen with spaces
  14. for(int i=0; i<HEIGHT; i++) {
  15. for(int j=0; j<WIDTH; j++) {
  16. screen[i][j] = ' ';
  17. }
  18. }
  19.  
  20. // Plot some "pixels"
  21. putpixel(screen, 10, 5, '*');
  22. putpixel(screen, 15, 8, '*');
  23. putpixel(screen, 20, 10, '*');
  24. putpixel(screen, 25, 12, '*');
  25. putpixel(screen, 30, 15, '*');
  26.  
  27. // Print the screen
  28. for(int i=0; i<HEIGHT; i++) {
  29. for(int j=0; j<WIDTH; j++) {
  30. printf("%c", screen[i][j]);
  31. }
  32. printf("\n");
  33. }
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
                                        
                                        
                                        
                                        
                                        
          *                             
                                        
                                        
               *                        
                                        
                    *                   
                                        
                         *              
                                        
                                        
                              *