Search:

Type: Posts; User: Malcolm McLean

Page 1 of 15 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    3
    Views
    1,494

    Print the data in the loops. To get an number...

    Print the data in the loops.

    To get an number on the interval 0-100 use modulus.
  2. Replies
    11
    Views
    1,268

    You can download it from here ...

    You can download it from here

    Basic Algorithms by Malcolm McLean (eBook) - Lulu
  3. Replies
    11
    Views
    1,268

    malloc is used in two situations; firstly when...

    malloc is used in two situations; firstly when you don't know how big an array needs to be until runtime, and secondly when you want to create a semi-permanent copy of an object that exists for a...
  4. Replies
    9
    Views
    796

    Parsing floats and integers is easy, just call...

    Parsing floats and integers is easy, just call strtod for a float and strtol for an integer. The hard part is getting the XML hierarchical structure successfully navigated

    I suggest you take a...
  5. You can't do this in standard C as there is no...

    You can't do this in standard C as there is no kbhit() or similar function which scans the keyboard for key presses.
    The stdin functions like getchar are line-based, they wait for the user to...
  6. Replies
    2
    Views
    610

    2D arrays don't work well in C when the...

    2D arrays don't work well in C when the dimensions are not known at compile time.

    So what most C programmers will do is to allocate a large 1D array, then access with



    array[y*width+x]...
  7. Replies
    10
    Views
    1,623

    No, you shouldn't normally need to flush printf()...

    No, you shouldn't normally need to flush printf() or fprintf().
    fclose() will flush fprintf(), but be aware that fclose() may fail. fprintf(stderr, fmt, ...) is supposedly unbuffered. Nowadays that...
  8. Replies
    3
    Views
    1,432

    Here's code for loading JPEGs and all the other...

    Here's code for loading JPEGs and all the other popular file formats for good measure.

    GitHub - MalcolmMcLean/babyxrc: Resource compiler, packages images, fonts, cursors, etc as compilable C...
  9. You need a lexer, to tell you what type of data...

    You need a lexer, to tell you what type of data is coming.
    In you case the lexer is simply + - or "number", but we might as well add * / and ().

    The you typically have factors, terms, and...
  10. Replies
    1
    Views
    597

    Consoles are line-oriented. So user composes a...

    Consoles are line-oriented. So user composes a whole line, then submits it to you. It follows that, at least at first, you should output and input whole lines.

    Print the prompt, followed by a...
  11. You need to learn about loops.

    You need to learn about loops.
  12. size_t offset = ((x * mat->columns) + y) *...

    size_t offset = ((x * mat->columns) + y) * mat->memSize;
    memcpy(mat->data + offset, data, mat->memSize);


    This looks suspicious to me though I haven't actually checked the logic thoroughly....
  13. Replies
    3
    Views
    1,790

    Assignments like these have the weakness that the...

    Assignments like these have the weakness that the best way of writing that particular program doesn't really scale up. Also, few real program conduct a dialogue with the user via stdin, if you do...
  14. You've been given half the story. In old C,...

    You've been given half the story.

    In old C, there was no "const" and


    char *string = "string"

    would create the pattern 's', 't', 'r', 'i', 'n', 'g', '0' in memory. You could then write to...
  15. The pattern you'll see in most professional...

    The pattern you'll see in most professional programs is




    /* get a uniformly distributed number p = 0 to 1 - episilon */
    #define uniform() (rand()/(RAND_MAX + 1.0))

    /* we can now use it...
  16. OK, so start by writing the function. It takes x...

    OK, so start by writing the function. It takes x as a parameter, and
    returns y.

    The next step is to convert from function space to graphics space.
    Do you want the y axis up or down? Where do you...
  17. Replies
    2
    Views
    589

    If you test it on a string which consists of all...

    If you test it on a string which consists of all spaces I believe it will fail.

    To fix it, add the terminating nul on your second pass. Then calculate end
    and do the third and final pass.
  18. Replies
    4
    Views
    1,128

    scanf and newlines are a nuisance. Basically the...

    scanf and newlines are a nuisance.
    Basically the scanf family of functions treat newlines like white space. There are ways of coaxing better behaviour out of them, but it turns the format string...
  19. Replies
    5
    Views
    1,498

    Oh that's it, obviously. That's why you have...

    Oh that's it, obviously.
    That's why you have sections which appear to be coherent and sections which aren't, when the shorts get
    in and out of synch.
  20. Plenty of people do use text format, largely...

    Plenty of people do use text format, largely because of the floating point portability reason.

    But you're not always in control of the format. RIFF files, for example, allow 32 bit floating
    point...
  21. Replies
    5
    Views
    1,498

    It's impossible that there should be a bug in...

    It's impossible that there should be a bug in fwrite itself.

    Firstly, you're not helping yourself by writing the file in a platform-dependent way.
    Set up two functions, fput16le (I believe wav...
  22. Replies
    7
    Views
    1,087

    Don't use wchar_t. UTF-8 works, until it...

    Don't use wchar_t.
    UTF-8 works, until it doesn't. Pass everything about as UTF-8, until you need
    code points instead of strings. Then just use int for the code point.

    Palindrome isn't...
  23. You need to be aware that, for historical...

    You need to be aware that, for historical reasons, 2D arrays in C and C++ are quite complex things that don't work well and simply, as in most programming languages. There's also an unfortunate...
  24. Portable floating point read/writes

    Generally, the code


    double x;
    FILE *fp;

    fwrite(x, 1, sizeof(x), fp);

    ...
  25. The important thing is your data structures....

    The important thing is your data structures.
    There are several ways of representing a sparse matrix. An obvious one is
    to create a little structure row, column, and value, then store the sparse...
Results 1 to 25 of 359
Page 1 of 15 1 2 3 4