I tried to use strtol but it's not converting right, *ptr is poiting to 10 and not a '\0' or '\n' when i insert a valid number such as 8.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int height, i, j, k, readOkay;
long int a;
char aux[20], *ptr;
do
{
printf("Enter height(0 to 8): ");
fgets(aux, 20, stdin);
a = strtol(aux, &ptr, 20);
printf("%ld", a);
printf("*ptr = %d", *ptr);
}
while ((a < 0) || a >8 || aux[0]=='0' || *ptr!='\n' || *ptr != '\0');
for (i = 0; i < height; i++)
{
j = (a + 1) - (i + 2);
k=0;
while (k < j)
{
printf(" ");
k++;
}
while (k < (a + 1))
{
printf("#");
k++;
}
printf("\n");
}
}