Search:

Type: Posts; User: Malcolm McLean

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    14
    Views
    150

    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...
  2. Replies
    14
    Views
    150

    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...
  3. 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....
  4. Open GL is the the obvious one. Getting Started...

    Open GL is the the obvious one.
    Getting Started - OpenGL Wiki
  5. Replies
    8
    Views
    529

    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...
  6. 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...
  7. 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());

    ...
  8. Replies
    4
    Views
    567

    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...
  9. Replies
    14
    Views
    760

    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...
  10. 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...
  11. 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...
  12. 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...
  13. Replies
    3
    Views
    556

    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...
  14. 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...
  15. 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...
  16. 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...
  17. Replies
    33
    Views
    1,224

    You've managed to create something which is...

    You've managed to create something which is correct C, but the wrong way to use pointers.

    createList returns a pointer to allocated memory. So you need to hold on to that pointer to free it later....
  18. It depends if you have to handle each case with...

    It depends if you have to handle each case with custom code or not. If all cases can be handled with the same code, then 480 is nothing. If you have to write separate functions for all 480 cases,...
  19. An array can be shuffled in N factorial...

    An array can be shuffled in N factorial combinations. If you are selecting M elements from a set, the number of selections you can make is N!/((M!) (N-M)!).

    If you are picking one element each...
  20. Multi-demensional arrays are often taught in...

    Multi-demensional arrays are often taught in beginners' books shortly after single dimensional arrays. I'ts not normally made clear that they are an advanced feature in C. If the array has dimensions...
  21. That's a brute force way of doing it. You can...

    That's a brute force way of doing it.

    You can construct a string to pass to system(). Use snprintf(), and test it first by outputting the command. Then write a real program that passes it to...
  22. Replies
    2
    Views
    530

    Bit fields are intended to reduce memory size....

    Bit fields are intended to reduce memory size. That's one of their main purposes. The other reason is to get a specific bit layout in memory for talking to hardware.

    But C compilers traditionally...
  23. Replies
    1
    Views
    439

    You need an array of structures from part one....

    You need an array of structures from part one. These have fields including doctor and date (is that surname? It's not clear to me from the format where the doctor is stored).

    You also need to...
  24. Replies
    1
    Views
    518

    The best place to start is with your data...

    The best place to start is with your data structures.
    Here it's quite simple. You need a struct with a single key / value pair, both strings. It probably mkaes sense to make them both char *s and...
  25. The goto cashier is suspicious and is probably...

    The goto cashier is suspicious and is probably the root of your problems.

    rename "main" something else, and write a new temporary main.

    This just opens a file for writing and writes some text...
Results 1 to 25 of 495
Page 1 of 20 1 2 3 4