random number program
hello i'm fairly new to C and theres this rather cruel program that my teacher has given me to solve.
it generates a x + y = ? equation with x and y being rather ridiculously large numbers and for some reason he made it so that if i don't calculate in 5 seconds, the program will shut down and the variables will be re-randomized.
i'd love some help on this. i've tried rather futile attempts on creating another program with the vague idea of using main(int argc, char *argv) to open the program and attain its variables and auto calculate it, but then i don't know how a calculator works lol. i tried googling on how to scan the program but then it comes up with things that are probably not needed to solve this.. like dll injection or something o.O.
It may be easier to help you if your explain your teacher's program a little more or provide us some code.
So your teacher's program prints out "x + y =" and then you have five seconds to input the correct answer? And you need to create a new program that solves it or do you need to edit your teacher's program?
unfortunately i have no access to the source code. yes it gives you 5 seconds to answer correctly or it resets and comes out with a new equation. im glad its always addition.
yup i have to create a new program that solves it.
thing is i tried making a sorta loop. i wrote program "a" to run the program that my teacher made and using srand/rand to generate my own random output with variables num1+num2. i used "num1=rand()%((999999-1)+1+1);". same with num2. i was wondering if "return num1+num2" would do anything even though i didn't use a function o_o. although this way i'd be waiting... quite a while. not that it worked properly anyway lol.
trouble was that because after my teachers program is run, after it shows the equation it sleeps straight for about 5 seconds during which my program can't do anything else.
apparently his previous student solved it by use of raw brain power. i envisioned the way numbers would have flown around inside the dudes mind o_o
i run my teachers program "randomness" and it spits out 193929 + 124121 = ?
if i type a wrong answer it gives me, "no!! lets study!".
hmm. it seems to be always within 6 digit numbers.
i asked him for a hint and he said "just hope for 1+1=?"
You still haven't said what it is you are actually supposed to do here, and what it has to do with C programming. You're just running his program, looking at the screen, and expected to type in the results in 5 seconds? Ok, so what's stopping you from grabbing a calculator and solving it and typing it in? What does this have to do with programming at all?
I believe he wants a program to save his "raw brain power", but it will take more brain power to come up with a program to do it for him.
And I bet the teacher would like him to learn that addition.
What type of course is this and what exactly are you studying? This is starting to sound like an intro program for disassembly practice. Don't think we can talk about disassembly on here.
lol what a dearie you are, Adak. you keeping in mind the equation isn't fixed? thanks anyway.
well, what im doing here is asking how my teacher program could be solved? i'm at a loss hence why i am looking for answers. the problem is in c code, so i assume that has something to do with c programming.
im studying information security.. maybe i am in the wrong place o_o?
teacher told me clearly the solution to this can be made with another program.
dont think it'll involve disassembling
yeahh im sure there are guys out there that can solve this by using a calculator. i just lack the hand eye co-ordination to punch in the digits fast enough. besides that im sure the purpose of the problem wasn't to learn how to use the calculate with a speedy hand.
annd if you start questioning the purpose of the question you could say that im supposed to do this on my own buuut i dont know where to look hmm.
i've been googling for 3 days but i seem to be on the wrong track!
course will move on without me solving this, but i just really wanna know lol
much appreciation for helpful replies
If you don't have access to the source code, then the only reason it would matter that the program was written in C would be to tell you that it was written in a language that can have lots of security holes to exploit. It just seems to me to be a disassembly problem. Is there anyway you can upload the program so that we can get a better idea of what exactly is going on? Perhaps, we're simply misunderstanding the specifications that you've posted.
Redirect the random program's stdin and stdout through your program, trap the text as it comes through the redirect pipe, let your program read the screen text, solve the equation then provide it's own answer back through the redirect...
Originally Posted by audgns7
Creating a Child Process with Redirected Input and Output
How to redirect Standard Input/Output of an application - CodeProject
How to spawn console processes with redirected standard handles
ah i'm sorry i can't upload the program. all of these problems are set up on his server and i have only read and run authority. hmm my apologies for not making this any easier
thank you CommonTater and failure67! time to read read read
Kind of funny, but I had this impression you were a brain damaged vet in re-hab, and re-learning arithmetic. <ROFL!>
Your problem is simplicity itself, *IF* your program is allowed to run.
Add in your stdio.h header and main(), and you should have a working program in jig time.
int n1, n2, sum=0;
fscanf(stdin,"%d %ch %d",&n1, &ch &n2);
sum=n1 + n2;
fprintf(stdout,"The sum is: %d\n",sum);
You may need to adjust the spacing in the fscanf() format, depending on exactly how the numbers and the + are presented.
lolol thank you. i'll have to try to type more clearly. my essays get remarked on as being "too vague" o_o
I wasn't talking about redirection using the command line... I meant redirecting the standard handles...
Open Pelles C... see the "output" window at the bottom... like that...
hurrah it worked out somehow!
thank you very kindly for your replies!