Search:

Type: Posts; User: comocomocomo

Page 1 of 2 1 2

Search: Search took 0.00 seconds.

  1. You are using "fread" with a variable called...

    You are using "fread" with a variable called "output". That is a bit strange.

    Did you open the file in read/write mode? Something like "w+b".

    Did you call "rewind()" or "fseek()" before trying...
  2. Quicksort tutorial - O(N*N) time and stack overflow when most input data are equal

    Hi guys,


    I'm writing this to point out a problem in the partition method proposed in your tutorial about quicksort:

    Quicksort - Cprogramming.com

    I already wrote a message to axon, the...
  3. Replies
    5
    Views
    1,270

    Of course not. Remove that * Please read...

    Of course not. Remove that *

    Please read carefully:
  4. Replies
    3
    Views
    861

    In your function Delete_Number() you iterate...

    In your function Delete_Number() you iterate through the array with only one variable. You should use two variables; one for the reading position and another one for the writing position. They both...
  5. Replies
    25
    Views
    2,883

    johngoodman, in the line 9 of your solution, you...

    johngoodman, in the line 9 of your solution, you seem to think that you are taking the number of the string and writing it in the variable num as if it was a decimal number. That is wrong. You are...
  6. Replies
    5
    Views
    1,270

    It's rather: phonebook_ptr[x].Surname But you...

    It's rather: phonebook_ptr[x].Surname

    But you also have to fix the input function. It always writes in the first element of the array.

    Don't write expresions at random. There is a logic reason...
  7. Replies
    5
    Views
    1,270

    It's great to see well formatted code for a...

    It's great to see well formatted code for a change :-)

    That global variable named 'counter' is a bad idea. Global variables are bad.

    Your problem is that you are always passing the same pointer...
  8. Oops, I posted this without seeing that there...

    Oops, I posted this without seeing that there were more comments in another page. Sorry.

    You are right Cat. I hadn't thought of that fact. The zeroes will appear together, and they can be wiped...
  9. Oh, and if you really need to count using the...

    Oh, and if you really need to count using the numbers that start with 1, you can do it using an array. You would have one element per digit of the counter. You would increase the least significant...
  10. The drawback of testing for zeroes (the solution...

    The drawback of testing for zeroes (the solution proposed by others) is that sometimes it might take a lot of time to get to the next value without zeroes. For example, if you are at number...
  11. Replies
    32
    Views
    3,979

    This is what I described: #include...

    This is what I described:



    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>


    #define DEFAULT_NUM_RECORDS 100
  12. Replies
    32
    Views
    3,979

    First, you should use the standard qsort(). Your...

    First, you should use the standard qsort(). Your code searches for a pair of elements to swap them, taking three assignments per swap. The most extended implementation of quicksort manages to reduce...
  13. Replies
    32
    Views
    3,979

    Then mmap() won't help, unless you want to use a...

    Then mmap() won't help, unless you want to use a raw binary file in your computer as a big cache of the database.

    mmap() would be the way to go if the data were in a huge binary file instead of a...
  14. Replies
    32
    Views
    3,979

    Stable sort has some relation with this. If you...

    Stable sort has some relation with this. If you use a stable sort, you can sort everything by the las column, then sort everything again by the first to last, and so on.

    Though, I would recommend...
  15. Sorry. That '1' confused me. So you are writing...

    Sorry. That '1' confused me. So you are writing to descriptor 1 instead of the new file?

    I don't understand the logic of your loop. You want to copy 512 bytes, but you only write if you actually...
  16. In every iteration of the loop... How many...

    In every iteration of the loop...

    How many bytes do you read?
    How many do you write?

    And yes, you need to read the rules and follow them. Otherwise you will just get ignored. Most people out...
  17. Replies
    23
    Views
    2,219

    I'm reading Scott Meyers' "Effective C++, 3rd...

    I'm reading Scott Meyers' "Effective C++, 3rd edition". I'm still with item 19, but I followed some cross references and ended up in item 46: "Define non-member functions inside templates when type...
  18. Replies
    23
    Views
    2,219

    You are right. I included inheritance in an...

    You are right. I included inheritance in an attempt to address the most general case.

    When using inheritance, you just need to write the operator<< once. I find this fact very interesting. That's...
  19. Replies
    23
    Views
    2,219

    Oh, and you might want B's print() to show the...

    Oh, and you might want B's print() to show the inherited part of the object by calling A's print():



    class B : public A
    {
    public:

    virtual void print (std::ostream & os) const
    ...
  20. Replies
    23
    Views
    2,219

    I think it's the other way around. If everything...

    I think it's the other way around. If everything is passed by reference, my design requires no copy operations. If you put the text in a std::string and then pass it to the op<< for strings, you...
  21. Replies
    23
    Views
    2,219

    In these cases I prefer to implement the...

    In these cases I prefer to implement the functionality in a public method (virtual, most of the times). The operator << receives a reference to the object and calls the virtual method.
  22. Replies
    23
    Views
    2,219

    Very interesting! Well, that narrows my list of...

    Very interesting! Well, that narrows my list of real-life, good 'friend' examples (from my own experience) to... zero ;-)
  23. Replies
    23
    Views
    2,219

    Suppose that you have to write your own STL-like...

    Suppose that you have to write your own STL-like container. The iterators might need to access the internals of the data structure. When you implement the ++ operator, for instance, you have two...
  24. Replies
    19
    Views
    3,141

    You don't need it in any other function, and...

    You don't need it in any other function, and global variables are bad. Leave it local but make it static. It will live like a global variable (whole program execution lifespan, initialized only...
  25. I think that your teacher doesn't want your...

    I think that your teacher doesn't want your program to insist in asking for a valid number.
    We can't help you any further without knowing the details of your assignment. I bet that they are very...
Results 1 to 25 of 45
Page 1 of 2 1 2