I need help , my code is not running and is the first time that the cpu icon is red or orange, never had happend that
I think that is an infinite loop.
Hi, @Guillermo2022!
The RAM/CPU counters can be fairly inaccurate and you shouldn’t face any problems regarding the speed of your Repl. These counters also take into account code intelligence and background processes, which vary from language to language. If you are running out of RAM/CPU power, you could choose to upgrade your current plan or boost your Repl.
But 2 days ago that code was running perfect, i dont know whta to do please help, literal 2 days ago a ran that program and worked perfect
Are you sure that you didn’t make any changes to the program within that two-day period?
100% and also Idk why but since those 2 days ago im feeling replit slow, but yeah, 100%
Adding onto @NateDhaliwal, you can tell that the loop is infinite due to the fact that your printf()
statement after was not executed (this could also be due to the fact that it is improperly indented) and C++ is an extremely fast language and would have finished looping before you would have had the chance to take a screenshot as well.
CC: @9pfs1 cause us C++ programmers don’t have to deal with char
declared strings
And why did I run the code two days ago, and in fact it is not the first time it has happened to me, since this morning any very very very simple and basic code is happening to me, but I do it again in another repl and the cpu bar
Actually, try leaving the program running for around a minute. Your program will eventually crash because your CPU power runs out, which is another way you can tell that loop is infinite. I don’t program in C (C++ programers have the simplicity of the string
datatype) but I’m sure other people could help you out.
I also copy as the code is in vs code is running ??
You are not initializing the x
variable. You need to initialize x
to 0
to start counting the characters or the program will go crazy.
Is the Repl private?
Do you mind making it public? It will be easier to help you.
It’s literally std::string
. Also a semicolon after a class is REQUIRED. YES, AFTER THE CURLY BRACE.
seems like the compiler that you use locally is optimised so it zeroes undefined variables (int x
).
But replit uses unoptimised clang
by default which does what your code literally asked for: it doesn’t change the existing value at the memory address assigned for x
. This value is likely to be larger than the size of palabra
, so it overflows past the buffer for palabra
and we don’t know when palabra[x]
will become \0
. Undefined variables → undefined behaviour.
You must give x
a value for the code to be portable.
int x = 0;
also AFAIK you should’ve got a warning about this, but they’re disabled by default
Run in Shell:
sed -i 's/Wno-everything/Wmost/' Makefile