There is a possibility that this may be a duplicate. However, I am just starting out with C and googling the issue only leads to questions which deal with more complicated situations.
Our class has been given some example code on printing variables:
#include <stdio.h>
int main() {
int i=10;
printf("i = %d\n", i);
return 0;
}
The lecture is over, and now it is time for the students to write code. The 1st exercise involves drawing shapes, so I have some code to draw a shape given a character and dimensions. It is not complete, because going further without pruning all of the errors I already have would be foolish.
#include <stdio.h>
void draw_rectangle(char c, int width, int length){
int i,j;
for(i=0; i<width; i++){
for(j=0; j<length; j++){
printf("%c\n",c);
}
printf("\n");
}
}
int main() {
draw_rectangle('*',4,4);
return 0;
}
Nevermind the fact that it seems like you can't declare and initialize variables in for loops. We have bigger fish to fry. I used printf to print a character much like printf was used in the example to print an integer. When I compile and run the code, nothing happens. This is an improvement over the program just crashing, but only slightly. What is the issue? I expected the following output:
****
****
****
****
Edit: Figured out the issue. I forgot to type a.out to check the output.