'How to print the alphabet with the 'write' function?

I have to print the alphabet using the write() function. I can not use printf() to see the output.

I have this so far:

#include <stdio.h>
#include <unistd.h>

char ft_print_alphabet(char);

int main()
{
    char ch;

    for(ch = 'a'; ch <= 'z'; ch++) {
        write(1, %ch, 26);
    }

    return(0);
}

I have tried to do this but I do not understand the write() function at all.



Solution 1:[1]

Write take the output id here you want 1 for default output on terminal it take a pointer of char, here you have only a char so pass the adress and write will get a pointer of size one char and last it take the number of char you want to print, here you display them one by one write do not by default print carriage return

int main()
{
    char ch;

    for(ch = 'a'; ch <= 'z'; ch++) {
        write(1, &ch, 1);
    }

    return(0);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Saren