Search:

Type: Posts; User: Malcolm McLean

Page 1 of 19 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    5
    Views
    203

    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.
  2. Replies
    5
    Views
    203

    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...
  3. 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....
  4. Replies
    4
    Views
    252

    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...
  5. 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...
  6. Replies
    4
    Views
    257

    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.
  7. 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...
  8. Thread: Dice

    by Malcolm McLean
    Replies
    12
    Views
    432

    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...
  9. Replies
    5
    Views
    213

    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++)
    {
  10. Replies
    2
    Views
    183

    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.
  11. Since you've only been programming for two weeks,...

    Since you've only been programming for two weeks, I'd suggest something simple.
    Just declare a struct with no variable-length fields for your "record" type. Store the structs as a flat array in...
  12. I've worked it out now. It is right. By...

    I've worked it out now. It is right.


    By subtracting one, if the number is odd, you zero out the last bit. If it is even, you zero out the fist set bit, and set all the following bits to one. But...
  13. You need to set count to zero before using it to...

    You need to set count to zero before using it to increment.

    The & operator performs a bitwise Boolean AND operation. Here it is masking off the lowest bit.

    You can always turn a loop into...
  14. Replies
    5
    Views
    246

    C doesn't allow for mixed type arrays. In C,...

    C doesn't allow for mixed type arrays. In C, arrays are always arranged with the elements consecutive in memory. So all elements have to be of the same size. In fact they also have to be of the same...
  15. Replies
    2
    Views
    244

    There are several ways of doing pathfinding....

    There are several ways of doing pathfinding. Really you need to be familiar with basic structures like trees and lists before you develop your own algorithm. On the other hand, developing your own...
  16. MUltidimensional arrays don't work well in C. A...

    MUltidimensional arrays don't work well in C. A lot of data structures are naturally two diemensional, but their dimensions are not known at compile time. Eg images.

    The normal thing to do is to...
  17. C's fopen takes a char *. This is a sequence of...

    C's fopen takes a char *. This is a sequence of 8-bit bytes designed to hold Latin characters. You might be able to pass it UTF-8, which encodes ASCII as 8 bits and Japanese as multibytes, but it...
  18. The comma operator is sometimes seen in for loops...

    The comma operator is sometimes seen in for loops where you have two index variables



    for (i=0; j = N-1; i < N; i++,j--)


    However even here many people frown on its use. Comma operators...
  19. C swept the board in the 1980s as the default low...

    C swept the board in the 1980s as the default low level general purpose programming language. Since then, there have been innumerable attempts to produce a "better C". The most successful has been...
  20. Yes, you need a do .. while rather than a while...

    Yes, you need a do .. while rather than a while loop here.
  21. Go onto my website (link below) and get the Baby...

    Go onto my website (link below) and get the Baby X resource compiler. It is designed for this job. It converts resources, mainly images, into C code.
  22. Replies
    5
    Views
    464

    It's mainly for porting. It means "reject...

    It's mainly for porting. It means "reject anything that isn't strictly ANSI-compliant". However in most beginners' exercises, you won't be doing anything that is platform-specific. So -pedantic can...
  23. Replies
    5
    Views
    464

    You've been thrown into an exercise in writing...

    You've been thrown into an exercise in writing functions before you understand printf. You need to be able to use printf() to get the results from your other exercises.

    printf() is a function in...
  24. Replies
    13
    Views
    415

    Say it's a Windows program. You can't easily show...

    Say it's a Windows program. You can't easily show a message passed to stderr to the user. So no library code that might be called from a Windows environment should rely on stderr being visible.
  25. Comment out everything except a line in main...

    Comment out everything except a line in main which prints out "Hello world". If it still segfaults then the problem is not in your source. Then gradually comment in to "Hello world" and comment out...
Results 1 to 25 of 457
Page 1 of 19 1 2 3 4