when i use random my settextstyle starts malfunctioning eg if i choose Gothic style i gives plain text if i make randomize a comment it works without bugs can anyone help me and also i heard void main is wrong and int main is correct why??

Dani AI

Generated

As pointed out, diagnosing this reliably requires a minimal, reproducible example. Without that, the usual culprits are either a symbol/header/ABI clash with a legacy RNG routine or undefined behaviour elsewhere that only becomes observable when you change calls (adding or removing a function call can change memory layout and timing). The C++ language documents why tiny edits can expose unrelated bugs: see Undefined behaviour.

Quick, practical checklist that finds most problems:

  • Build with maximum warnings (for GCC/Clang use -Wall -Wextra -Wshadow) and fix every warning.
  • Run with sanitizers (AddressSanitizer / UndefinedBehaviorSanitizer) to catch memory or UB issues. See the sanitizers docs: AddressSanitizer and UndefinedBehaviorSanitizer.
  • Look for name collisions or missing/incorrect headers. Nonstandard, old functions can collide with library symbols; ensure the function you call is the one you expect.
  • Avoid mixing object files or libraries built with different compilers or incompatible runtimes; that often produces bizarre behaviour in GUI/graphics code.

Prefer standard, well-specified facilities:

  • Use modern C++ random facilities instead of nonstandard helpers; see <random>. Example pattern:
    
    #include <random>

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dist(0, 99);
int value = dist(gen);

- Use a standards-compliant `main` signature. The authoritative description is here: [main](https://en.cppreference.com/w/cpp/language/main).

int main()
{
return 0;
}



If the issue occurs only when using an old graphics library (BGI/graphics.h) or an outdated compiler, check that the graphics headers/libraries match the toolchain. Isolate the problem to the smallest program that reproduces it; that quickly reveals whether it is a symbol clash, UB, or a runtime mismatch.

Recommended Answers

All 3 Replies

The description of your problem is at best vague and at worst confusing...Being able to see the code that's actually causing you the problem would help!
So if you could post some code it would help us to help you! (Just don't forget the code tags!)


Also, regarding your question about void main vs int main....Well that particular issue has been discussed numerous times here on Daniweb.
Take a look at:
http://www.daniweb.com/forums/thread109415.html
or:
http://www.daniweb.com/forums/thread78955.html

Cheers for now,
Jas.

i solved it by using a substitute function rand();

thx for ur help mate

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.