fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4.  
  5. char * drawRectangle(unsigned int height, unsigned int width){
  6. int row, col;
  7. char *myArray = malloc(100);
  8.  
  9. int i = 0;
  10.  
  11. while(myArray[i] != '\0'){
  12. for(row = 0; row<height; row++){
  13. printf("\n");
  14. for(col = 0; col < width; col++){
  15. if( row ==0 || row == height-1 || col == 0 || col == width-1){
  16. printf("*");
  17. myArray[i++] = '*';
  18. }
  19. else{
  20. printf(" ");
  21. myArray[i++] = '\n';
  22. }
  23. }
  24. }
  25. i++;
  26. }
  27. return myArray;
  28. }
  29.  
  30. int main() {
  31. char *c = drawRectangle(3,3);
  32. if(c == NULL){
  33. printf("%s", c);
  34. }
  35.  
  36. return (0);
  37. }
Success #stdin #stdout 0s 2240KB
stdin
Standard input is empty
stdout
Standard output is empty