Member Avatar for Member #956681

I have been reading this eBook called C Programming for the Absolute Beginner, Second Edition.

I'm starting to get the hang of the logic at the moment

Something just struck my mind.

If a person wanted to build a program for photo editing. Kept It simple and basic only for cropping, lighting, and filters of all colors.

If a person wanted to build a photo editing program

Would the person write the code like this I won't use any punctions in the code at the moment since I am new and learning the ropes.

A person would write

"Okay Mr program you will crop photos once the mouse Is seletected and highlighted"
"You will have all sorts of colors from red, blue, orange, green, black, maple wood"
"Your lighting will be all sparks and flame lights, fire lights, dangerous sparks for lighting"

Would this be a way to write this kinda of program? I'm just making up the sentence as fictitious.
Or would it need more work?

C Is all about writing text and thinking logically. If I not mistaken correct me If I am.

Dani AI

Generated

Natural-language sentences like the ones in the first post are useful as a requirements sketch, but they are not C code. The sketch must be translated into precise data structures, algorithms and I/O steps, then expressed with C syntax. C gives direct control over memory and bytes; that control is powerful but unforgiving. ’s idea is a good starting brief; it needs to be broken into explicit operations before any real code appears.

A practical decomposition to go from sketch to working tool:

  • file I/O: pick a strategy to read/write common formats (use a library rather than hand-parsing every format).
  • image model: represent width, height, channels and row stride explicitly.
  • kernels: implement single-pixel ops (brightness, grayscale) first; then neighborhood ops (blur, sharpen).
  • pipeline: load → transform → save. Keep GUI/interaction separate from pixel code.
  • testing: make small command-line programs that apply one filter at a time.

Example kernel (tiny C skeleton using single-file loaders such as stb_image/stb_image_write; brightens RGB channels only):

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include <stdio.h>

int main(int argc, char **argv) {
    if (argc != 3) return fprintf(stderr, "usage: %s in.png out.png\n", argv[0]), 1;
    int w,h,comp;
    unsigned char *data = stbi_load(argv[1], &w, &h, &comp, 0);
    if (!data) return fprintf(stderr, "load failed\n"), 2;
    float factor = 1.2f;
    int pixels = w*h;
    for (int i = 0; i < pixels; ++i) {
        unsigned char *p = data + i*comp;
        for (int c = 0; c < comp && c < 3; ++c) {
            int v = (int)(p[c] * factor);
            p[c] = (unsigned char)(v > 255 ? 255 : v);
        }
    }
    stbi_write_png(argv[2], w, h, comp, data, w*comp);
    stbi_image_free(data);
    return 0;
}

Troubleshooting notes: watch channel order and alpha, respect row stride/padding, clamp arithmetic to avoid overflow, and free memory. As observed, real image editors cover many edge cases; examining mature projects and isolating core kernels before adding GUI code is the fastest path. As implied, C’s simplicity in rules does not mean it is forgiving—iterate in small steps.

Recommended Answers

All 4 Replies

The text is the code. Logic is how you apply algorithms (patterns for processing data) to data. This latter part is the difficult part. Image processing is VERY difficult. There are a gazillion factors to take into account, such as pixel depth (number of bits per pixel), size of image (x pixels vs. y pixels), shading, rendering, ray-tracing (if you are doing synthetic image generation), etc. My advice (after 30+ years doing this stuff) is to study well-written tools that do this. There are a plethora of tools in the FOSS (Free and Open Source Software) domain that do it. One great example is GNU's Gimp package. Study that. Understand that. And you may be ready to start writing some of this stuff on your own.

Well, for a design document, I suppose it's a start. You would need a lot more detail, however, even before you could consider writing any actual code.

If your actual goal is to write a photo editing program, well, that's about as complex as any project you could have chosen. I think I personally would tackle just about anything else first before trying something that difficult... and I do systems programming as a hobby.

BTW, despite this book's title and the opinions of far too many 'educators', neither C nor C++ make a good language for beginners; they are both designed for experienced, professional coders, especially C, and they both are far too difficult for most newcomers. I would recommend a language like Python or Ruby as a better place to start, though that is a personal opinion and completely subjective (actually, I would really recommend Scheme, but there you're getting a bit too outré for most people).

Member Avatar for Member #956681

I see I should stick with Python then :D lol no wonder C was complex for me now.
I don't know why people say C Is easy to deal with and every beginer starts with C, guess every beginer should start with python.

There really isn't any one language which all beginners start with, and no language appeals to everyone; the real issue is that a lot of universities start people off with C (or worse, C++), despite it being poorly suited for most beginners.

As for complexity, C is actually a rather simple language, compared to Python. This is not the same as saying it is an easy language by any stretch of the imagination. C is simple in the same way chess is simple: it has relatively few rules and very few exceptions to those. It still takes years to master either of them, and starting of with them before any others is, for most people, an exercise in frustration.

(To follow the analogy, Scheme and the other Lisp languages are like go: there are hardly any rules to the game at all, and learning how to play takes just a few hours, but mastery is a lifetime's work. Conversely, C++, Java and Perl are like Brockian Ultra Cricket or - mountains of rules and variations thereof, more than any one person could ever really learn. But that's still better than C# and VB.Net, which are like TEGWAR - the rules seem to slip and slide around at random and no one will tell you all of them, and eventually you end up under the table with a massive headache.)

Python is more like, say, your typical video game. It has a lot of complex aspects to it, but it also hides a lot of that complexity from you by doing most of the really troublesome things for you. A video game player doesn't have to worry about the refresh rate of the monitor, or the details of how sprites are moved around the screen; they can focus on playing the game. Likewise, Python programmers don't need to worry much about the mechanisms of memory management or list implementation. Python lets you focus on the programming rather than getting bogged down in details which aren't really important to a new programmer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.