Search:

Type: Posts; User: Malcolm McLean

Page 1 of 18 1 2 3 4

Search: Search took 0.01 seconds.

  1. 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...
  2. 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...
  3. 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...
  4. Yes, you need a do .. while rather than a while...

    Yes, you need a do .. while rather than a while loop here.
  5. 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.
  6. Replies
    5
    Views
    333

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

    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...
  8. Replies
    13
    Views
    312

    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.
  9. 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...
  10. You don't really need to learn operating systems...

    You don't really need to learn operating systems to write a virtual machine. Just use the host machine operating system and provide a layer of abstraction.

    You might find this book interesting...
  11. Replies
    13
    Views
    312

    That's what we call a "religious question". Most...

    That's what we call a "religious question". Most people typedef C structs as a matter of course, a few refuse to do so. If you don't typedef, you don't pollute the global namespace, and also it is...
  12. Replies
    5
    Views
    253

    You can implement it like this. int...

    You can implement it like this.



    int tolower(int ch)
    {
    const char *upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const char *lower ="abcdefghijklmnopqrstuvwxyz";

    char *ptr =...
  13. Make a "cell" structure which consists of a...

    Make a "cell" structure which consists of a character pointer and a double. When the character pointer is null, the double data is valid, unless it is NaN, when the cell is empty. This approach won't...
  14. Start by writing macros or functions min2 / max2....

    Start by writing macros or functions min2 / max2. These take two numbers and return the minimum, maximum.

    Then build min3(), max3() on top of those functions.

    Now the bounding box is upper left...
  15. Replies
    14
    Views
    574

    To calculate an average you need a list of...

    To calculate an average you need a list of numbers. The simplest form of list is an array. In C we usually need to keep the count of items in the array in a separate variable. Unlike high level...
  16. Replies
    8
    Views
    469

    The scaling code looks wrong to me. Normally you...

    The scaling code looks wrong to me. Normally you assume that the origin of the model is the point you scale about. So scaling is a simple scalar multiply.

    If you are not scaling round the model...
  17. The only strings you should have in the program...

    The only strings you should have in the program are the digits 0-9, the special cases "eleven", "twelve", and "thirteen", the suffix "teen", the special cases "ten", "twenty", "thirty",...
  18. Replies
    4
    Views
    331

    Yes, you can call C from C++ because there is the...

    Yes, you can call C from C++ because there is the "extern C" mechanism. You can't call C++ from C, with the exception of C++ functions marked "extern C". So usually the best thing to do is to write...
  19. You want to malloc such large variables....

    You want to malloc such large variables.
    Declaring them as locals will blow the stack, as others have pointed out. Declaring them as globals will work but might lead to odd behaviour if the OS can't...
  20. Replies
    12
    Views
    438

    C uses curly brackets to indicate blocks. YOu...

    C uses curly brackets to indicate blocks. YOu need to read some C code to get the idea of the syntax.
  21. Replies
    4
    Views
    387

    It depends on your compiler. Building a library...

    It depends on your compiler. Building a library is not something you'll do for practical purposes much as a beginner. You might be asked to build one as a learning exercise.

    A library is basically...
  22. Whilst not related to your actual problem, the...

    Whilst not related to your actual problem, the temporary should be a T, not a T &.
  23. Replies
    5
    Views
    403

    So you need an input string, and room for an...

    So you need an input string, and room for an output string the same length of the input string. So your function signature is



    /*
    Reverse odd-numbered words in a phrase
    Params: output -...
  24. Replies
    23
    Views
    1,212

    C doesn't allow code like this area =...

    C doesn't allow code like this



    area = width * height;
    height = 4;
    width = 5;
    // expect area to be 20
  25. Replies
    4
    Views
    771

    You are creating two instances of class "B", one...

    You are creating two instances of class "B", one owned by main, the other owned by class A.
Results 1 to 25 of 441
Page 1 of 18 1 2 3 4