User Profile

Collapse

Profile Sidebar

Collapse
Savage
Savage
Last Activity: Jul 20 '11, 10:33 AM
Joined: Feb 28 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Savage
    replied to Problem With Deleting characters from string (C)
    in C
    Code:
          for(j = 0; j < strlen(y); j++){
               if(x[i] == y[i]){ // x[i] == y[j], instead
                x[i] = -1;
                  break;
                     }
                  }
                }
    Think that should be it.

    Savage
    See more | Go to post

    Leave a comment:


  • Savage
    replied to How to pass objects to constructor?
    in C
    If you are going to use pointers then this is fine if one,two,three are pointers as well to a Vertex.. if they are still references then you need to use address-of operator(&) infront of one,two and three to properly initialize v1,v2,v3 pointers(or change the constructor to accept pointers instead of references) If what you are building is some small project you'll be fine by doing like this, if its going to be something bigger those reference...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to How to pass objects to constructor?
    in C
    You can, but you need to create the object on the heap and not on the stack like you did here since after function call all local variables of the function get wiped out, so you would return a pointer to some garbage.

    Write it like this instead:

    Code:
    Vertex* generateRandomVertex()
    {
       //generate random x,y,z-values
       Vertex* pointer = new Vertex(x,y,z);
       return  pointer;
    }
    ...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to How to pass objects to constructor?
    in C
    Because vertices contained in Triangle class are real objects and not references, and therefore they need to be constructed. Since initializer list runs "before" constructor, the problem can be solved in this way since the list uses the inbuilt assingment operator .. but what if later on you want to return a Vector by value from some function? Like this:

    Code:
    Vector generateRandomVector()
            {
                //generate
    ...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to How to pass objects to constructor?
    in C
    If you write your own constructor the built-in default constructor seizes to exist, so you will have to write it(the default constructor) by yourself.

    Regards,
    Savage
    See more | Go to post

    Leave a comment:


  • Savage
    replied to How to define range for a standard type?
    in C
    In worst case you can use preprocessors #define directive to do so:(not really recomendable,be tter use compiler switch)

    Code:
    #define char signed char
    See more | Go to post

    Leave a comment:


  • Difference is that cin.get(ch) returns an istream object, while cin.get() returns the read character as an integer.

    First version allows you to more easily read the stream in a loop because it returns an istream object which got boolean conversion so you can do the following(e.g):

    Code:
    char c;
    while(cin.get(c))
    {
       //do something
    }
    , instead of having to do:

    Code:
    char c;
    while(cin.fail()==false)
    ...
    See more | Go to post
    Last edited by Savage; Jan 21 '11, 08:08 AM. Reason: Fixed small typo: Thanks tdlr :)

    Leave a comment:


  • Savage
    replied to How to read and manipulate an avi file in C?
    in C
    Manipulating AVI files on your own is completly unrecomendable considering how many codecs are there(you would need to write seperate code to handle most common types of codecs atleast..), so its much better if you can find some library that already does it for you. DirectShow is quite good, but its written as a set of C++ classes. You could write some wrapper code to alow you to use it with C code only, or you could try to find some crossplatform...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to How to use pointers in this example?
    in C
    Code:
    int main(double Q[6][6], int i, int j, int k)
    Main can't have parameters like these ones.It's either parameterless or it got two parameters which it recievies from the command line.Secondly, those variables(Pk,a_ p,A,A_t..) are local and exist only inside
    Code:
    void prioriestimate ()
    function. If you want to return variable from a function you either need to change return type to the type of variable you want to return(in case you want...
    See more | Go to post

    Leave a comment:


  • Take a look at this.

    Regards :)
    See more | Go to post

    Leave a comment:


  • I dont know what you mean with "my file managment code, otherwise its fine", but I do see a lot of goto's which is a bad thing, since they ruin program flow and make it less readable.Genera lly, you can write every structured programme without using goto's and in most cases you should go that way.So use goto's only when they are necessary (which is a rare thing) and use other language constructs to structure your code in a more readable...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to Random number in output of my C++ file
    in C
    Your function area doesn't return the value, so some random number is inserted by the compiler and printed by cout << area.area() << "\n";
    See more | Go to post

    Leave a comment:


  • It's because of this:

    Code:
     TestWrapper(const string s) { vObj.push_back(s); }
    vObj is vector of type Test, but you are pushing a string into it, so implicit conversion happens because your Test has constructor which accepts string as a argument, therefore another Test instance is created and filled with text "HELLO" and thats the first line of your output.But the temporary that was created on stack inside the TestWrapper(con st...
    See more | Go to post

    Leave a comment:


  • Code:
    double chips, milk, cola, coffee, total, zipcode, quantity_chips, 
               quantity_milk, quantity_cola, quantity_coffee, payment, pin, error, tax,   
               final_cost;
    Why are all of your variables except for option of type double?
    See more | Go to post

    Leave a comment:


  • Savage
    replied to missing initializer?
    in C
    Looks like you have forgot to initialize tp_version_tag element of the structure.
    See more | Go to post

    Leave a comment:


  • Savage
    replied to Hacking protection. How to do that?!
    in C
    Then you are looking after RACS: A Referee Anti-Cheat Scheme for P2P Gaming...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to Hacking protection. How to do that?!
    in C
    Well I think many software companies would like to know solution to that.
    If something like that existed they wouldn't spend millions on state of the art protection, which in the end still fails to do it's job.

    Probably the best protection is over the internet, like the master servers in online games which check for original cd keys. You would agree that is probably a lot harder to hack master server, then it is to hack client...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to Stringifying a vector
    in C
    With great power comes great responsibility :P

    ,kind regards

    Savage...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to Letter question
    in C
    ungetc() may help, check this out.

    You will ofcourse need to modify the sample a bit ^^...
    See more | Go to post

    Leave a comment:


  • Savage
    replied to Stringifying a vector
    in C
    Did you include <string> ?

    Also stream are usually on the left side,not variables, did you try this instead:

    temp >> result;

    ,of result << temp?
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...