I have a homework that's supposed to ask the user for a number and make a square with the length being the number they put. If the user types in 5, then the program needs to make a square that is 5x5.
When I compile it, i get a segmentation fault (core dumped). I have no idea where the problem is. Can you guys help me? I even tried running the program with paper and pencil to see what my output would be and it seemed fine to me.
#include <stdio.h>
int main (){
int size, limit = 0;
char ch = 'A';
int rows = 1;
printf("Enter size:\n");
scanf("%d", size);
while (limit <= size){
if (rows == 1 || rows == size){ /* This only works in first and last row */
printf("%c", ch);
limit++;
}
if (rows != 1 && rows != size){ /* This only works if row is not 1 and last row*/
do{
printf("%c", ch);
limit++;
do {
printf(" ");
limit++;
} while (limit != size -1);
limit++;
if (limit == size){
printf("%c", ch);
rows++;
limit = 0;
printf("\n");
}
}while (rows != 1 && rows != size); /* while not in first AND last row */
}