Search:

Type: Posts; User: Malcolm McLean

Page 1 of 20 1 2 3 4

Search: Search took 0.02 seconds.

  1. Replies
    2
    Views
    117

    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])
  2. 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...
  3. 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...
  4. 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...
  5. Replies
    5
    Views
    302

    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...
  6. Replies
    35
    Views
    974

    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...
  7. Replies
    6
    Views
    573

    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...
  8. Replies
    16
    Views
    798

    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...
  9. Replies
    16
    Views
    798

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

    Open GL is the the obvious one.
    Getting Started - OpenGL Wiki
  12. Replies
    8
    Views
    698

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

    ...
  15. Replies
    4
    Views
    796

    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...
  16. Replies
    14
    Views
    1,100

    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...
  17. 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...
  18. 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...
  19. 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...
  20. Replies
    3
    Views
    720

    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...
  21. 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...
  22. 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...
  23. 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...
  24. Replies
    33
    Views
    1,813

    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....
  25. 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,...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4