3 ms·
>So of course, the "logical" thing to try was to write a .bat and save it with a different extension and see what happened. Ha ha, same here. Also the next thi
by eriknstr 9y ago
>So of course, the "logical" thing to try was to write a .bat and save it with a different extension and see what happened.
Ha ha, same here. Also the next thing I did was to open exe files with notepad and conclude that this is what real code looked like and that the programmers that wrote the programs had written it that way.
When a little bit later I learned that programs were written in languages like C++, I got a book about C++ while on vacation and I read a bit in that book and I wrote down the Hello World program on paper and wrote variations of it and a couple of programs that would ask questions and say something. When I got back from vacation I sat down in front of my computer, typed in hello world and used a compiler called Bloodshed C++ which the book had recommended and compiled the program and double-clicked the exe file, only to have it open a window and immediately close. I had failed to understand that I needed to run the program via cmd.exe because of course Hello World exits immediately when it's printed the text.
This discouraged me a bit so I stayed away from programming languages for several years after that but at least I kept learning HTML and a bit about reverse engineering and a couple of other things and eventually I got back to programming when I started high school and we were using Texas Instruments TI-84 Plus calculators and we were given a couple of programs written in TI-BASIC which we were told to store on our calculators. Once I'd written some programs of my own in TI-BASIC I then read a book about PHP and wrote some PHP.
Such was the beginning of my experience with programming.
- Sharlin 9y ago> I had failed to understand that I needed to run the program via cmd.exe because of course Hello World exits immediately when it's printed the text. And till this day, people writing command-line programs in an IDE like Visual Studio stumble on this fact, and the workaround is still the same: adding an stdin read or something like system("PAUSE") at the end, pausing the execution until the user hits Enter.
- to3m 9y agoBest solution I've found: static void PressEnter(void) { if(IsDebuggerPresent()) { fprintf(stderr,"press enter\n"); getchar(); } } Then from somewhere right near the top of main or whatever: atexit(&PressEnter); You can throw in some isatty calls, or #ifdef _CONSOLE, or if(GetConsoleWindow()), etc., but the above pretty much always does the right thing.
- int_19h 9y agoOr you can flip the switch in the IDE itself to pause on exit.