My Code : A Program to Print from a to z
My file name : ft_print_alphabet.c
#include <unistd.h>
int ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_print_alphabet(void)
{
char c;
c = 'a';
while (c <= 'z')
{
ft_putchar(c);
c++;
}
}
My Issue:
I use the MinGW & Vim editor and I get the following error while I compile in MinGW.
$ gcc ft_print_alphabet.c
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
I understand that the compiler doesn't know from where it should start the program since it couldn't locate void main()
in the code.
My code works fine when I replace ft_print_alphabet(void)
with void main(void)
but please note this is the standard way of coding where I am going to apply for a c coding camp.
This code and the function ft_print_alphabet(void) 'must' be used. I know there are other simple ways to do the same code but please note I'm not looking for using the function ft_print_alphabet(void)
.
How can I execute the program without adding void main()
instead of void ft_print_alphabet(void)
.
I need my program to start executing from the function void ft_print_alphabet(void)
. How can I do that please? Is there any command like:
gcc ft_print_alphabet.c | ft_print_alphabet
?
gcc ft_print_alphabet.c ft_print_alphabet
?
Something like this?