Search:

Type: Posts; User: Malcolm McLean

Page 1 of 20 1 2 3 4

Search: Search took 0.02 seconds.

  1. Replies
    4
    Views
    2,488

    It's hard to answer because no-one would write a...

    It's hard to answer because no-one would write a function to muliply a real value by two. It must be placeholder code.

    If you are calculating one value, return it as a "double" (not a double *)....
  2. Replies
    4
    Views
    3,292

    You can rewrite any loop as a set of recursive...

    You can rewrite any loop as a set of recursive calls. There's a school of thought that you should do that. However not normally in C, but in a so-called "functional" programming language. Scheme is...
  3. Replies
    4
    Views
    2,799

    Some things you can fake up in C, other things...

    Some things you can fake up in C, other things you can't do without effectively writing an interpreter for another language in C. The main C limitation versus C++ that can't be overcome is the lack...
  4. It's very nearly an executable file. It's...

    It's very nearly an executable file. It's compiled machine code with labels attached. So you can't actually run it. However it's relatively simple to replace the labels with addresses (linking) and...
  5. 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...
  6. 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...
  7. Replies
    2
    Views
    5,414

    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])
  8. 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...
  9. 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...
  10. 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...
  11. Replies
    5
    Views
    3,941

    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...
  12. Replies
    35
    Views
    20,270

    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...
  13. Replies
    6
    Views
    13,641

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

    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...
  15. Replies
    16
    Views
    14,221

    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...
  16. 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....
  17. Replies
    4
    Views
    5,660

    Open GL is the the obvious one. Getting Started...

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

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

    ...
  21. Replies
    4
    Views
    5,494

    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...
  22. Replies
    14
    Views
    10,317

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