Ok, I managed to fix it.. here's the fixed code, I hope this will help others:
# include <stdio.h>
# include <stdlib.h>
int main()
{
int t,spaceNum=0,d=0,counter=0,i, j, k, n;
printf("Enter triangle height\n");
scanf("%d", &n);
if (n < 2) return 0;
printf("Enter the number of $\n");
scanf("%d", &d);
printf("Enter number of spaces\n");
scanf("%d", &spaceNum);
printf("\n");
for (i = 0; i< n ; i++)
printf(" ");
printf("*\n");
for (i = 1; i<n-1 ; i++)
{
for (j = n - i; j>0; j--)
printf(" ");
printf("*");
for (k = 0; k<2 * i-1; k++)
if (k >= 1 || k<(2*i-1))
{
counter = counter + 1;
if (counter == d+1)
{
for (t = 1; t <= spaceNum; t++)
{
printf(" ");
}
counter = 0;
}
else printf("$");
}
printf("*\n");
}
printf(" ");
for (i = 1; i<=2* n-1 ; i++)
printf("*");
printf("\n");
printf("\n");
printf("The height of triangle is %d\n", n);
printf("The number of $ is %d\n", d );
printf("The number of space is %d\n", spaceNum);
getchar();
getchar();
}