Thread: Garbage output without cout, printf or another ...

  1. #1
    Registered User albert_sps's Avatar
    Join Date
    Mar 2008
    Location
    Tegucigalpa
    Posts
    6

    Unhappy Garbage output without cout, printf or another ...

    When I run a program a lot of characters are showed at end of program execution, although i don't use any like cout or printf functions that could display variables.

    This occurs when I execute program twice or more times.

    I'm using malloc and free to allocate a block of 60000 chars.



    The code is here... At first post.
    Some garbage is displayed also if I remove all printf functions...
    Last edited by albert_sps; 03-22-2008 at 06:51 PM. Reason: More information about this issue

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Ah yes, this must be solar rays from outer space affecting your your processor in such a manner that it prints characters to your screen. Nothing you can do about it really.

    The above was an answer that was as useless as your question. When your car breaks down, do you go to a mechanic without your car, and ask him: "Hey, my car broke down. What's wrong with it?" He can't fix it without having the car or for that matter tell you what's wrong with it without taking a peek at the engine.

    Where's your code?

  3. #3
    Registered User albert_sps's Avatar
    Join Date
    Mar 2008
    Location
    Tegucigalpa
    Posts
    6
    Well, i'll get some GC library. Althougt use INT 21,4A to modify allocated memory block should help, theoretically....

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Are we stuck in the stone age?
    Mostly likely, a GC library won't help because you are using freed memory or have memory corruption somewhere or the like.
    Garbage Collection libraries make sure you don't get leaks.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well looking at the code I see at least two very serious memory trashing opportunities.

    > cmd[0] = (char) strlen(argv[3]);
    And where is cmd pointing? - answer, nowhere in particular. Certainly not anywhere you can be sure is safe to write to.

    > memset(par, 0, sizeof(par));
    Frankly I'm amazed this compiled without warnings even on a crusty fossil compiler.
    The first parameter should be &par
    Who knows what you just filled with a bunch of zeros.

    With such an old compiler, you really need to know what you're doing because it will generally compile anything which is syntactically valid regardless of how little sense it makes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    GCC to the rescue
    =========================================
    Everytime you segfault, you murder some part of the world

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Huh?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    ^ Salem dissed the compiler the OP used, so I recommended GCC
    =========================================
    Everytime you segfault, you murder some part of the world

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well... then, I must recommend Visual Studio. It is far better IMHO. Safe library, very powerful debugging facilities, so easy to install & use & configure, even the compiler itself. This assumes Windows, of course.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    I couldn't get a single thing running on visual studio, it gave me linker errors. I can't be bothered to figure out linker errors when all I try to run is a simple hello world program, imagine the errors i'd get if I tried to run more complex programs.
    =========================================
    Everytime you segfault, you murder some part of the world

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Pfft. You don't know what you're doing, that's all.
    It's no different than any other linker. You get errors sometime.
    And you can get errors if you choose the wrong project type, too.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why does printf output include a trailing 'D'
    By musikluvah in forum C Programming
    Replies: 5
    Last Post: 01-16-2006, 04:38 AM
  2. Whats Wrong Whith This!?
    By SmokingMonkey in forum C++ Programming
    Replies: 8
    Last Post: 06-01-2003, 09:42 PM
  3. Replies: 4
    Last Post: 04-01-2003, 12:49 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 06:59 PM