Whoops you have an infinite loop here

//This creates a LCV for the do loop below and sets it equal to 0.

int y = 0;

//This do loop generates the random number.
do
{
    //This generates a random time seed.
    srand(time(0));

    //This generates a random number between 1 and 99.
    ran = rand() % 100;

    //This while controls the do loop.
}while (y != 9);

y is initialized to 0 and you are looping while y!=9. And that is just the first error, there might be more.


Bug #2

int z = 1;
//This makes the program only create a random number the first pass through the loop.
if (z < 2)
{
    //This runs the random number generator function.
    return randomgen();

    //This sets the result of the function as the random number.
    randnum = randomgen();

    //This sets the random number to the current number.
    num = randnum;
}

After fixing infinite loop in randomgen(), You are immediately returning...

Answer from Tony Tannous on Stack Overflow
๐ŸŒ
Is It Down Right Now
isitdownrightnow.com โ€บ onlinegdb.com.html
Onlinegdb.com - Is Onlinegdb Down Right Now?
Onlinegdb.com has been rated 3.9 out of 5 points. A total of 43 votes cast and 0 users reviewed the website. ... Once added to your toolbar, this button will let you to check the status of a site from your browser's toolbar. Just drag the text your bookmarks bar : Down Right Now? Do not share my Personal Information.
Discussions

performance - Why won't my program run in GDB online compiler/debugger or Visual Studio C++ 2019 - Stack Overflow
Bring the best of human thought ... at your work. Explore Stack Internal ... Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 5 years ago. ... I just finished writing this code and am ready to start debugging and testing. However, when I try to run it in GDB the console ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Why is onlineGDB not giving the same result as another compiler?
Thank you for your contribution to the C++ community! As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework. When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed. Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc. Homework help posts must be flaired with Homework. ~ CPlusPlus Moderation Team I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/Cplusplus
8
1
May 4, 2024
Online GDB doesn't work as expected?
Through some checking on godbolt , it appears OP is using a GCC with version 6.3 or older. What you are essentially asking is, why does GCC, at a given version, decide to reserve 48-bytes on the stack for what appears to only be 32-bytes worth of data (using 8 bytes for the int). My answer: I don't know. Could be a bug, could be bad optimization, could be oversight, could be for some other reason or no reason at all. Using GCC version 7.1 or newer results in the function reserving 32-bytes on the stack as you would expect. More on reddit.com
๐ŸŒ r/C_Programming
4
2
December 2, 2021
St-link (Gdb server) not working
Did it ever work with GDB server? I had something like this happen to me once though it was working previously and the solution was the following, taken from here: https://github.com/stlink-org/stlink/issues/1012#issuecomment-751650320 Basically you need to use a board that has a reset button/pin and to hold reset when connecting to the ST-link. When connected, let go of the button and if you try several times and get lucky with the timing it should connect. afterwards just do a mass erase More on reddit.com
๐ŸŒ r/stm32f4
2
3
September 17, 2021
๐ŸŒ
OnlineGDB
onlinegdb.com
GDB online Debugger | Compiler - Code, Compile, Run, Debug online C, C++
Online GDB is online compiler and debugger for C/C++. You can compile, run and debug code with gdb online. Using gcc/g++ as compiler and gdb as debugger. Currently C and C++ languages are supported.
Top answer
1 of 2
3

Whoops you have an infinite loop here

//This creates a LCV for the do loop below and sets it equal to 0.

int y = 0;

//This do loop generates the random number.
do
{
    //This generates a random time seed.
    srand(time(0));

    //This generates a random number between 1 and 99.
    ran = rand() % 100;

    //This while controls the do loop.
}while (y != 9);

y is initialized to 0 and you are looping while y!=9. And that is just the first error, there might be more.


Bug #2

int z = 1;
//This makes the program only create a random number the first pass through the loop.
if (z < 2)
{
    //This runs the random number generator function.
    return randomgen();

    //This sets the result of the function as the random number.
    randnum = randomgen();

    //This sets the random number to the current number.
    num = randnum;
}

After fixing infinite loop in randomgen(), You are immediately returning...

2 of 2
1

you have two problems in your code: the first one is that you have infinite loop in randomgen() function the condition in check against y - y != 9 but the value never update

int randomgen() 
{
    //This creates a variable to store the random number.
    int ran;

    //This creates a LCV for the do loop below and sets it equal to 0.
    int y = 0;

    //This do loop generates the random number.
    do
    {
        //This generates a random time seed.
        srand(time(0));

        //This generates a random number between 1 and 99.
        ran = rand() % 100;

        //This while controls the do loop.
    }while (y != 9);

    //This returns the random number for use in the rest of the program.
    return ran;
}

and the second one is even if you pass the loop in the function you exit main right away because the call to the function randomgen() is with return

if (z < 2)
{
    //This runs the random number generator function.
    return randomgen(); <-- **second problome**

    //This sets the result of the function as the random number.
    randnum = randomgen();

    //This sets the random number to the current number.
    num = randnum;
}
๐ŸŒ
OnlineGDB
question.onlinegdb.com โ€บ 9748 โ€บ why-my-code-is-not-working-plz-help
Why my code is not working plz help !!!! - OnlineGDB Q&A
April 11, 2021 - As you have used to scanf functions for num1 and num2, the third scanf function is not read because of '\n' left by the previous scanf functions ยท To make your code work just use scanf(" %c",&ch); instead of this scanf("%c",&ch);
๐ŸŒ
OnlineGDB
question.onlinegdb.com โ€บ 14516 โ€บ why-wont-it-stop
Why wont it stop - OnlineGDB Q&A
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
Find elsewhere
๐ŸŒ
OnlineGDB
question.onlinegdb.com โ€บ 10202 โ€บ problem-forming-new-files-and-writing-on-them
Problem forming new files and writing on them - OnlineGDB Q&A
Hello! So I'm using this online compiler for my easy class problems in c++. Now I'm solving one, ... and it worked as a charm for the past 2 years.
๐ŸŒ
OnlineGDB
onlinegdb.com โ€บ login
Login | GDB online Debugger
If your program is reading input from standard input and you forgot to provide input via stdin. Your program contains infinite loop, which may never break. Your program contains infinite recursive function calls. May be your program is trying to process large data and it takes much time to ...
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ online gdb doesn't work as expected?
r/C_Programming on Reddit: Online GDB doesn't work as expected?
December 2, 2021 -

I am posting this both on r/Assembly_Language and here. I think the topic involves both fairly strongly.

So, I am going to do a presentation involving buffer overflows and I learned some basic Assembly because of that (more specifically the function prologue). I plan on learning Assembly for real and have installed SASM, but for now I just know basic C. I need help reading something.

In one of my sources (https://www.tenouk.com/Bufferoverflowc/Bufferoverflow4.html), this guy does disass in his vulnerable function in order to show that sub has allocated more space than he declared (4 vs 20).

This is his code:

#include <unistd.h>

 

void Test()

{

   char buff[4];

   printf("Some input: ");

   gets(buff);

   puts(buff);

}

 

int main(int argc, char *argv[ ])

{

   Test();

   return 0;

}

And this is the output of disass Test:

0x080483d0 <Test+0>:    push   %ebp

0x080483d1 <Test+1>:    mov    %esp, %ebp

0x080483d3 <Test+3>:    sub    $0x8, %esp

0x080483d6 <Test+6>:    sub    $0xc, %esp

Buff is 4 bytes and 20 bytes are "freed" on the stack. But when I try to do the same with a relatively more complicated function (I hope commentary is enough for the language gap):

#include <stdio.h>
#include <string.h>
#include <locale.h>     
#include <stdlib.h>        

void senha(){      
 char senha[10];           
    char senhareal[10]="dddddd";      
    int teste = 0;    
    char resposta[3]; 
    
    printf("\n\n\n\n-----------------------------SISTEMA NUCLEAR DA OTAN------------------------------------ \n\n\n\n");     
    
    
    printf("DIGITE SUA SENHA: ");
    gets(senha);


    if(0 == strncmp(senha, senhareal, 20))
    {
         printf ("\nSenha correta! \n");
         teste = 1;    
    }
    
    
    else
    {
        printf ("\nSENHA INCORRETA! \n");
    }


    if(teste)
    {
        printf ("\nO usuรกrio agora controla a instalaรงรฃo! Deseja destruir o Brasil? \n");     
        gets(resposta); 
    }
            }

int main(){               
    system("color 03");
	setlocale(LC_ALL, "Portuguese"); 
    senha();  

    return 0;
}

I get this:

0x0000555555555209 <+0>: endbr64
0x000055555555520d <+4>: push %rbp
0x000055555555520e <+5>: mov %rsp,%rbp
0x0000555555555211 <+8>: sub $0x30,%rsp
0x0000555555555215 <+12>: mov %fs:0x28,%rax
0x000055555555521e <+21>: mov %rax,-0x8(%rbp)

No matter my input. So why does Online GDB consistently subtract 48 bytes? What are the instructions following sub and do they apply at all to what I am trying to do? Is it possible to know what's going on in that specific platform? Finally, am I unable to replicate what this person did with my code?

I tested the code of my source in Online GDB as well. It consistently subtracts 16 bytes.

๐ŸŒ
OnlineGDB
question.onlinegdb.com โ€บ 1577 โ€บ does-code-work-fine-onlinegdb-but-work-when-compiled-with-gcc
Why does my C code work fine in onlineGDB but not work when compiled with gcc? - OnlineGDB Q&A
There are no compiler errors, but the program does not work despite being the same exact code. It's ... with >gcc -Wall -Wextra -Werror Thanks!
๐ŸŒ
OnlineGDB
question.onlinegdb.com โ€บ 13693 โ€บ why-dont-files-work-c
Why don't files work (c++)? - OnlineGDB Q&A
January 1, 2023 - The code works fine, you just have to have file.in file in your project (alongside the main.cpp) that has two numbers separated by white space
๐ŸŒ
Implantsdesigned
implantsdesigned.com โ€บ gdb-online
Online GDB doesn't work as expected? : rC_Programming
IMPLANTSDESIGNED.COM This domain name is for sale. Owning a suitable domain name will help you achieve greater success in your career. For any business consultation about IMPLANTSDESIGNED.COM, please contact us! ! !
๐ŸŒ
OnlineGDB
question.onlinegdb.com โ€บ 8457 โ€บ why-doesnt-it-work-correctly
Why doesn't it work correctly? - OnlineGDB Q&A
Hi there! I was set to find minimum value of the function (y) wlile argument (x) is 0.3
๐ŸŒ
SaaSHub
saashub.com โ€บ status pages โ€บ development โ€บ design playground
OnlineGDB Down? OnlineGDB status and issues.
There are no reported issues during the last 24h. Use the 'Report an Issue' button to report any issues you may have with the service. Check out our list of OnlineGDB alternatives. ๐Ÿ‡จ๐Ÿ‡ฆ A user from Canada reported Website not opening as a problem with OnlineGDB about 7 days ago.
๐ŸŒ
UpDownRadar
updownradar.com โ€บ status โ€บ onlinegdb.com
Onlinegdb down today September, 2025? Onlinegdb.com not working for me or everyone else?
Onlinegdb.com website down Today September, 2025? Can't log in? Real-time problems and outages - here you'll see what is going on.
๐ŸŒ
Doj.me
doj.me โ€บ onlinegdb.com
doj.me
2025 Copyright. All Rights Reserved
๐ŸŒ
OnlineGDB
onlinegdb.com โ€บ contact
Contact Us | GDB online Debugger
If your program is reading input from standard input and you forgot to provide input via stdin. Your program contains infinite loop, which may never break. Your program contains infinite recursive function calls. May be your program is trying to process large data and it takes much time to ...