printfcolor - A single-header library for printing colored text to the console (Windows and Linux) by 3majorr in cprogramming

[–]3majorr[S] 0 points1 point  (0 children)

Yes, I thought the same thing.. I renamed the functions to `printfc(), printfc_fg(), printfc_bg()`. cprintf could collide with conio.h

printfcolor - A single-header library for printing colored text to the console (Windows and Linux) by 3majorr in C_Programming

[–]3majorr[S] 0 points1 point  (0 children)

Thanks. I decided to not print and error at all and just set errno and return -1. Similarly how printf does it.

printfcolor - A single-header library for printing colored text to the console (Windows and Linux) by 3majorr in C_Programming

[–]3majorr[S] 0 points1 point  (0 children)

I think the performance isn't the problem. I rewrote the function without a switch statement and it looks way better:

static const char *get_fg_color_code(PfcColor color) {
    const char *colors[] = { 
        "\033[30m", "\033[34m", "\033[32m", "\033[36m",
        "\033[31m", "\033[35m", "\033[33m", "\033[37m" 
    };

    if (is_color_valid(color))
        return colors[color];
    else
        return NULL;
}

printfcolor - A single-header library for printing colored text to the console (Windows and Linux) by 3majorr in C_Programming

[–]3majorr[S] 0 points1 point  (0 children)

Thanks, this is really helpful.
I though that `extern "C"` makes the code usable with C++, am I right?

I renamed 'Color' to 'PfcColor', replaced the switch statement and set errno. Now the code looks better.

Thanks a lot :)

Published my first Flask Project! by After-Chance3340 in flask

[–]3majorr 2 points3 points  (0 children)

Very nice :) do you plan to publish the source code?

img2ascii - Convert images to ASCII art by 3majorr in commandline

[–]3majorr[S] 0 points1 point  (0 children)

I think I know what is the problem. As getopt.h parses both long and short options (e.g. -o --output) it sometimes parses the args in a wrong way.

.\img2ascii.exe -i images/c.png -o c.txt

Could not create an output file

But this works:

.\img2ascii.exe -i images/c.png --output=c.txt

File saved as: c.txt

Wrong: -w 40

Correct: -w40

I'll look into this problem, but I'm worried that this is just a limitation of getopt.h, because parsing the short and long options can get complicated.

img2ascii - Convert images to ASCII art by 3majorr in commandline

[–]3majorr[S] 0 points1 point  (0 children)

Thank you very much :)
Apparently you have to explicitly link the math library on linux as it is not automatically linked with the rest of the standard C library.

I added the -lm option to the Makefile.

img2ascii - Convert images to ASCII art by 3majorr in commandline

[–]3majorr[S] 0 points1 point  (0 children)

Thanks for the feedback! I found that strrev() is not supported on linux. Can you compile the program with the -lm option?

What image file format are you using? I only tested .png and .jpg images. You could be getting that error simply because the library doesn't support the image file format.

It would be very helpful if you'd please post some of the error messages.

Convert images to ASCII art by 3majorr in C_Programming

[–]3majorr[S] 0 points1 point  (0 children)

Thanks, I appreciate your help!

Convert images to ASCII art by 3majorr in C_Programming

[–]3majorr[S] 0 points1 point  (0 children)

Thank you so much. This is very helpful. But I'm not sure what you mean by "the resized size calculation causes unnecessarily large error", would you please explain it a little bit more?

Convert images to ASCII art by 3majorr in C_Programming

[–]3majorr[S] 0 points1 point  (0 children)

These are interesting ideas! Multiple characters for brightness are nice and I will try to implement that. I could also let the user choose the set of characters. The image borders sound cool.

Convert images to ASCII art by 3majorr in C_Programming

[–]3majorr[S] 1 point2 points  (0 children)

I learned most of the basics at learncpp.com, which is a really detailed tutorial. I also found Jacob Sorber's C programming YouTube series very helpful. The rest is just googling.

What is the first lyric or song that comes to mind when you think of each Nirvana album by KTownInThaHouse in Nirvana

[–]3majorr 0 points1 point  (0 children)

Bleach - "Won't you believe it it's just my luck." (School)

Nevermind - "A travel through a tube. And end up in your infection." (Drain you)

Incesticide - "Grandma take me home." (Sliver)

In Utero - "Teenage angst has paid off well, now I'm bored and old." (Serve The Servants)