Search:

Type: Posts; User: Malcolm McLean

Page 1 of 19 1 2 3 4

Search: Search took 0.01 seconds; generated 8 minute(s) ago.

  1. Replies
    1
    Views
    93

    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...
  2. 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...
  3. Do you understand what is going on? There are...

    Do you understand what is going on?

    There are at least two standard IO implementations on your system.
    When the MINNGW library is used, your macro is defined. It also happens to be defined to...
  4. Replies
    5
    Views
    275

    Do you mean one bit or one byte? Most computers...

    Do you mean one bit or one byte? Most computers address memory in 8 bit bytes. In C, and int is usually 4 bytes, or 32 bits.

    A boolean variable is logically one bit, either on or off. However C...
  5. free(ptr); printf("\n\nFreeing ptr: \n");...

    free(ptr);
    printf("\n\nFreeing ptr: \n");

    /* not sure whether this is allowed or not. sizeof() is a compile
    time operator rather than function, so it is probably OK */
    ...
  6. A C program needs several memory areas. The...

    A C program needs several memory areas. The executable code itself, the stack, the heap, and global data. Global data is usually then divided into read-only memory, initialised memory, and memory...
  7. Replies
    3
    Views
    234

    You need a buffer of three results. The easiest...

    You need a buffer of three results. The easiest way to do this
    is via a small array

    char results[3];

    initialise to some value which is neither heads nor tails, because you must toss the coin...
  8. It's a mathematical problem rather than a...

    It's a mathematical problem rather than a programming problem, and certainly rather than a C problem.

    An entire industry is based onthe premise that factoring large integer with large prime...
  9. Use this interface void zeroCrossings(const...

    Use this interface

    void zeroCrossings(const float *x, bool *crossings, int N);

    The array crossings is the same length as the input array x, but each position represents the line between...
  10. Replies
    3
    Views
    331

    Should be fine. Almost certainly you have an...

    Should be fine. Almost certainly you have an error elsewhere
    in the code. For example when printing the result out.
  11. Replies
    3
    Views
    300

    Undo is always difficult to program. The easiest...

    Undo is always difficult to program. The easiest way is to have a list of all previous states. Fortunately a tic-tac-toe board is only a few bytes, so there's no real issue in memory or performance....
  12. Most beginners' C books introduce 2D arrays...

    Most beginners' C books introduce 2D arrays iimmediately after 1D arrays.

    This is a mistake. Multidimensional arrays were historically not implemented well in C, and should be thought of as an...
  13. Sort the list. Since it's a linked list, you...

    Sort the list.

    Since it's a linked list, you can't use qsort. Mergesort is a good linked list sort algorithm.

    Now it's trivial to pick out the unique instances. A unique instance is either the...
  14. The local variables in main are pushed first on...

    The local variables in main are pushed first on to the stack. Notionally in the order in which they are declared, though the optimiser may make some changes and you can't rely on this if playing...
  15. Replies
    1
    Views
    336

    If you are new to programming, then it's best to...

    If you are new to programming, then it's best to work through a C primer using just the standard library to learn the core language, before tackling any SDK.

    If you know some programming, C has...
  16. Replies
    5
    Views
    586

    We're not a free homework-doing service for...

    We're not a free homework-doing service for people who have difficulty with their assignments.
  17. Replies
    5
    Views
    586

    You just ned some more complicated logic in your...

    You just ned some more complicated logic in your inner for loop.
    The outer for loop iterates over the size of the input.
    The inner for loop needs to output a series of dashes, followed by a varying...
  18. In C, string are passed around as char *'s. They...

    In C, string are passed around as char *'s. They are arrays of char
    terminated with a NUL. Since you have a buffer, you need to
    call the function strcpy() to copy your input strings to this buffer....
  19. Replies
    4
    Views
    433

    You use fgets like this char string[1024];...

    You use fgets like this



    char string[1024];
    fgets(string, 1024, stdin);


    User is very unlikely to enter 1024 characters. Probably you only expect 20 or so. But it's usually hard to give a...
  20. If you're advanced enough to write a minesweeper...

    If you're advanced enough to write a minesweeper game then you should be past the stage where people have to point out this type of bug in your code on the forum. Every C programmer gets segmentation...
  21. Replies
    4
    Views
    495

    structs are padded for alignment purposes....

    structs are padded for alignment purposes. acctNum will be 4 bytes, lastName 16 (1 pad), firstname 12(2 pad) and balance 8 bytes.
  22. You want to open the text file, as binary. Call...

    You want to open the text file, as binary. Call fopen "rb".

    When you compress it, you're not treating it as a text file any more. You're treating it as a sequence of bytes. Similarly, the...
  23. Thread: Dice

    by Malcolm McLean
    Replies
    12
    Views
    690

    If 6 means "roll again and add six" then this is...

    If 6 means "roll again and add six" then this is impossible.

    The object of the exercise seems to be to get the mean. This isn't entirely simple, and it's one of those things that is maybe easier...
  24. Replies
    5
    Views
    346

    You've got six lines. Then on each line you've...

    You've got six lines. Then on each line you've got 1, 2, 3, 4, 5, 6 values.

    So that bit is easy. Your skeleton is



    for (i=0; i < 6; i++)
    {
    for (j = 0; j < 6; j++)
    {
  25. Replies
    2
    Views
    319

    You should exit(EXIT_FAILURE); rather than with a...

    You should exit(EXIT_FAILURE); rather than with a constant to be portable. However most OSes don't have a strong concept of a process "failing". It can be hard to define for many real programs.
Results 1 to 25 of 470
Page 1 of 19 1 2 3 4