Search:

Type: Posts; User: Malcolm McLean

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. University professors shouldn't give exercises...

    University professors shouldn't give exercises like this.

    C doesn't have good facilities for parsing input. You have to write from scratch on the top of low level functions. To do a really solid...
  2. Change making is a difficult problem. It's...

    Change making is a difficult problem. It's usually easy to find a trivial solution (all units), and a better algorithm (take the highest note and subtract until you can do no more, then repeat with...
  3. Replies
    2
    Views
    328

    int main(void) { int array[5] = {2, 4, 6,...

    int main(void)
    {
    int array[5] = {2, 4, 6, 1, 5};
    int j, k;

    for (j =0; j < 5; j++)
    for (k = 0; k < 5; k++)
    {
    char compare;
    if (array[j] < array[k])
  4. Yes. You need to know what font your output...

    Yes. You need to know what font your output device is using.
    Standard C has no functions for querying a font, but your platform will. Since getting the width of a string is such a common...
  5. Unless someone here has the exact same system,...

    Unless someone here has the exact same system, they can only speculate. One possibility which has been mentioned is that char_array2 is a pointer, in which case sizeof() will yield a value of...
  6. It's not quite clear what you want to do. But say...

    It's not quite clear what you want to do. But say we want 1 to represent 'a' and 26 to represent 'z', and we want to write to a string at a position, we can write a function like this



    void...
  7. Replies
    5
    Views
    453

    The way I would do it is to take a list of...

    The way I would do it is to take a list of filenames on the commandline, open them, and write the contents to stdout.
    Basically the Unix "cat" command.
    User can then do what he wants with the...
  8. Replies
    35
    Views
    1,406

    The days when you had to pay for a compiler are...

    The days when you had to pay for a compiler are over. Visual Studio is free, and is a highly capable C++ (and therefore C) compiler.

    Here's the old Windows file API

    Fileapi.h header - Win32...
  9. Replies
    6
    Views
    755

    If parent_t contains a pointer to a child_t...

    If parent_t contains a pointer to a child_t rather than an instance of a child_t, then you have to create the memory space for the child_t somehow. That can be by using malloc, or if you don't want...
  10. Replies
    16
    Views
    1,029

    So if the absolute value is greater than two you...

    So if the absolute value is greater than two you repeatedly divide by two, otherwise you repeatedly multiply by two, until you have a number in the form 1.xxxxxx. The number of steps gives you the...
  11. Replies
    16
    Views
    1,029

    The answer is to use the frexpf() function to...

    The answer is to use the frexpf() function to decompose a float into exponent and mantissa. Internally it will be doing bit shifting and masking and you can write your own version on similar...
  12. You want to work with a copy of the command line...

    You want to work with a copy of the command line argument. It's
    not a good idea to modify the argv[] strings in place.

    So call malloc() with strlen(argv[1]) + 1 (for the nul), then strcpy....
  13. Open GL is the the obvious one. Getting Started...

    Open GL is the the obvious one.
    Getting Started - OpenGL Wiki
  14. Replies
    8
    Views
    800

    Matrices can be hard to understand. It's easier...

    Matrices can be hard to understand. It's easier when you think of them as something concrete rather than an abstract "matrix". When I'm teaching matrices, I use football as an example. Say you've got...
  15. Start with the function isvowel(char ch) that...

    Start with the function isvowel(char ch) that tells you whether a character is a vowel or not. Then build countvowels(char *str) on top of it.
    That's the logic for you program.
    Now the hard part is...
  16. define two macros. One is uniform(), which create...

    define two macros. One is uniform(), which create a random number on 0-1. The other is lerp, which interpolates between a and b by paramter t, on 0-1.

    So


    x = lerp(-1.0, 1.0, uniform());

    ...
  17. Replies
    4
    Views
    926

    I don't think that's a good idea. It's best to...

    I don't think that's a good idea. It's best to write your own tar attempt first, then worry about how the actual tar implementation does it later.

    Tar collapses a directory into one file. A...
  18. Replies
    14
    Views
    1,239

    Computers can run out of memory. But if you are...

    Computers can run out of memory. But if you are making valid allocations in a small beginner's program on a desktop machine, this is very unlikely.

    You need to test the return from realloc() for...
  19. It's really a signals processing issue rather...

    It's really a signals processing issue rather than a C issue.

    The body of the sound (dot dash) can be either a pure sine wave or a combination of sine waves. In a real application you would...
  20. UTF-8 is backwards compatible with ascii, which...

    UTF-8 is backwards compatible with ascii, which is a huge advantage. UTF-16 has the disadvantage that it can't represent some code points, whilst UTF-32 is rather extravagant if most of the text is...
  21. C strings are terminated by 0 (nul), not newline....

    C strings are terminated by 0 (nul), not newline.

    In C, strings are basically just arrays of 8 bit ascii values arranged in memory. There's jsut a little bit of special syntax to allow you to...
  22. Replies
    3
    Views
    809

    struct A has to be padded to 8 bytes so that it...

    struct A has to be padded to 8 bytes so that it is correctly aligned when you set up an array of them. struct B contains an identical struct to A, plus anohter member. So it's 8 bytes, plus one byte...
  23. That is probably a mistake. You can make it work...

    That is probably a mistake. You can make it work for small binary numbers, but it's not very logical and hard to error check.

    If you understand strings, you are best off entering the binary as a...
  24. When you are setting up a function pointer, you...

    When you are setting up a function pointer, you should always pass back a void * supplied by caller. qsort() doesn't do this, which doesn't matter much as the function pointer is usually a trivial...
  25. If they are all non-negative, just set to the...

    If they are all non-negative, just set to the negative, as Salem suggests. Note that in C, = means "assign".

    If some are negative, and you want them all to be negative, then you need to test them...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4