#include<stdio.h>
#include<unistd.h>
void ft_putchar(char x){
write(1, &x, 1);
}
void ft_print_comb()
{
char i, j, k;
i = '0';
while(i <= 7){
i ;
j = i 1;
while(j <= 8){
j ;
k = j 1;
while(k <= 9){
k ;
ft_putchar(i);
ft_putchar(j);
ft_putchar(k);
ft_putchar(',');
ft_putchar(' ');
}
}
}
}
int main(){
ft_print_comb();
return 0;
}
I have tried to do couple changes but it either broke the code or kept giving me no output. What I am trying to do is create a function that displays all different combinations of three different digits in ascending order, listed by ascending order. for loop and printf functions are not allowed.
CodePudding user response:
i is a character with a value of 48 (the ASCII code of '0') so the while loop is never entered. Set i this way:
i = 0;
CodePudding user response:
Since you are using char
s, you should compare with character literals instead of integers. For instance, the while
loop is never entered because the ASCII code for '0' is 48, which is greater than 7.
while (i <= '7') {
i ;
j = i 1;
while (j <= '8') {
j ;
k = j 1;
while (k <= '9') {
k ;
ft_putchar(i);
ft_putchar(j);
ft_putchar(k);
ft_putchar(',');
ft_putchar(' ');
}
}
}