Advertisement
Guest User

Sample code

a guest
Oct 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.73 KB | None | 0 0
  1. #include <unistd.h>
  2.  
  3. void    ft_putchar(char c)
  4. {
  5.     write(1, &c, 1);
  6. }
  7.  
  8. void    ft_print(int width, char a, char b, char c)
  9. {
  10.     int w_counter;
  11.  
  12.     w_counter = 0;
  13.     while (w_counter < width)
  14.     {
  15.         if (w_counter == 0)
  16.             ft_putchar(a);
  17.         else if (w_counter == width - 1)
  18.             ft_putchar(b);
  19.         else
  20.             ft_putchar(c);
  21.         w_counter += 1;
  22.     }
  23.     ft_putchar('\n');
  24. }
  25.  
  26. void    rush(int width, int height)
  27. {
  28.     int h_counter;
  29.  
  30.     h_counter = 0;
  31.     while (h_counter < height)
  32.     {
  33.         w_counter = 0;
  34.         if (h_counter == 0)
  35.         {
  36.             ft_print(width, 'A', 'C', 'B');
  37.         }
  38.         else if (h_counter == height - 1)
  39.         {
  40.             ft_print(width, 'C', 'A', 'B');
  41.         }
  42.         else
  43.         {
  44.             ft_print(width, 'B', 'B', ' ');
  45.         }
  46.         h_counter += 1;
  47.     }
  48. }
  49.  
  50. int     main(void)
  51. {
  52.     rush(1, 1);
  53.     rush(10, 10);
  54.     rush(1, 1);
  55.     rush(1, 5);
  56.     return (0);
  57. }
  58. /*
  59. This is a piece of code I was able to write myself after completing that group project on the harder pyramid building project I had. Albeit, it is a simple piece of code, but given I am just starting out in C and programming again, I am proud of it because to me it was the first time things clicked and showed me how code can do tasks extremely fast. The idea of the program was simply to print out a pattern box of respective size based off user input and the box would determine whether it is a side, corner or interior to fill it with a respective character. I felt that I wrote it efficiently made it very readable by others. Users would be able to switch out the characters of choice based on how they want the box to look. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement