Results 1 to 15 of 15

Thread: printf itself

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Question printf itself

    Hi,
    I want to write a program that print its code. I saw the solution one time but it's wrong and I don't understand it. It's in C (but I use .Net compiler) (and if anyone know a solution in C++ or other language too, I'll happy).
    See this....(don't ask me about char(38) please..I don't know).
    How is the solution, please?

    thanks..
    Attached Files Attached Files
    Regards

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: printf itself

    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. The following user says thank you to Michiel for this useful post:

    mickey (29th September 2007)

  4. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: printf itself

    it seems that my iostream (.net2005) doens't contains method 'form' for cout (cout.form).
    Is one other "C++" way to print? (apart printf). thanks.
    Regards

  5. #4
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: printf itself

    Quote Originally Posted by mickey View Post
    it seems that my iostream (.net2005) doens't contains method 'form' for cout (cout.form).
    Is one other "C++" way to print? (apart printf). thanks.
    I don't know any of this newfangled .NET stuff, but in C++ the standard way to print to standard output is with iostreams and the redirection operator.

    cout << "Hello world!" << endl;

    You can do the same with any other iostream derived object, including file streams.

  6. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: printf itself

    I need a function C++ like printf to use char %c %s inside it.
    cout.form was able to do this; But it seems vanished.
    Regards

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: printf itself

    If you want your application to print its code, then the worst possible solution is the one you are using: store the code as a string in the actual code.

    A better solution is to make the application store the code(by parsing the source files)in a separate module that will be distributed also. The module should preferably be encrypted, so only trusted users can see the code.
    Last edited by marcel; 29th September 2007 at 20:30.

  8. #7
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: printf itself

    That's cheating.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: printf itself

    What do you need it for anyway?

  10. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: printf itself

    Quote Originally Posted by wysota View Post
    What do you need it for anyway?
    here, http://www.nyx.net/~gthompso/self_c++.txt
    as Michiel said, there is what I need. But as you can see there is the use of cout.form, and my compiler seems don't know it. I could use the printf but I'm looking for a pure c++ function where I can use %c %s characters....
    Regards

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: printf itself

    But it doesn't say what you need it for

  12. #11
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: printf itself

    Quote Originally Posted by wysota View Post
    But it doesn't say what you need it for
    I don't understand 'for': I need it to write a program that print its code. Have you see in the example link how cout.form is used? Is there a similar function that work as it?
    Regards

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: printf itself

    Quote Originally Posted by mickey View Post
    I don't understand 'for': I need it to write a program that print its code.
    Is it just for fun? For school? For any practical use? I'm just curious.

    Is there a similar function that work as it?
    try std::string and its sprintf method (I think it has one). Then you can redirect the result to cout.

  14. #13
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: printf itself

    OK!! It is just for fun. But I think your target in your question was another. Is it so? I'm curious too.....
    But I don't find fprintf method in string; but if it's used to write on a file as said before it's a cheat...
    Regards

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: printf itself

    Quote Originally Posted by mickey View Post
    OK!! It is just for fun. But I think your target in your question was another. Is it so? I'm curious too.....
    No... I don't think so.
    But I don't find fprintf method in string; but if it's used to write on a file as said before it's a cheat...
    sprintf not fprintf. You sprintf what you want to printf into a string and then "printf" it (by redirecting) to cout

    Something like:
    Qt Code:
    1. std::string str;
    2. str.sprintf("Format %s", "xyz");
    3. std::cout << str << std::endl;
    To copy to clipboard, switch view to plain text mode 

    Just make sure std::string::sprintf really exists.

  16. #15
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: printf itself

    it doesn't exist as part of string....(at least in .net); but I wonder where's the "form" method....
    Regards

Similar Threads

  1. Redirect printf to QTextEdit?
    By Randulf in forum Qt Programming
    Replies: 9
    Last Post: 12th October 2006, 14:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.