Page 1 of 1

TEXT PAD FOR C PROGRAMMING ASAP PLEASE !thx

Posted: Thu Sep 18, 2003 3:12 pm
by ak
IVE LEARNT JAVA USING TEXT PAD...but i wanna know how to use c over text pad....i've dowloaded the compiler off borland and stuff...now i just dled txt pad...what things do i need to do ...to transfer over....i want it to compile the C script and not try to compile it as a java script is there an option to toggle this??? and what steps do i need to do...details please...thx

Posted: Thu Sep 18, 2003 4:40 pm
by s_reynisson

Posted: Thu Sep 18, 2003 8:00 pm
by mo
Hope you don't mind my riding along on this one too!

Very first few pages learner here!

I have managed to set up TextPad to compile, and to run the program in DEBUG mode per the help files and the link above. I am having a little grief just running the program per the help files. What is happening is that a command window (Windows 2K Pro) is being opened, and I am being prompted for the information I am suppoed to enter, then the Command window presumably completes the work of the program and exits so quickly that I cannot see the result.

Here is the little first program that I am running (as soon as I put in the correct answer...zap the command window is closed. I would like it to remain open until I close it.:

Code: Select all

#include <iostream>
using namespace std;

int main()
{
   short Secret;
   short Guess;

   Secret = 3;

   cout << "try to guess my number. Hint: It's from 0 to 9"<<endl;
   cin >> Guess;

   while ( Guess != Secret)
   {
   cout << "Sorry, that's not correct."<<endl;
   cin >> Guess;
   }

   cout << "You guessed right!"<<endl;

   return 0;
}

Posted: Thu Sep 18, 2003 10:25 pm
by Bob Hansen
Doesn't this belong in Java forum?
===================================
Ignore this.....my error (thanks MudGuard)....Sorry about that.
Hmmmm, why can't I delete this?
Bottom of forum says I can but..........?

Posted: Thu Sep 18, 2003 10:34 pm
by MudGuard
No, as it is about C/C++...

Posted: Thu Sep 18, 2003 10:42 pm
by mo
I think this BB allows delete until someone has answered. Then you need to be sneeky and come in with some entirely different text and pretend you never said what someone thought they saw you say. Deny Deny Deny...

Posted: Fri Sep 19, 2003 3:56 am
by talleyrand
Hey Mo,
I'll be happy to field this one. Your program is executing exactly as it should--- It collects your input until you hit the correct condition. It prints a final message and exits. What you need to do is force the program to pause before it exists. I don't have Borland installed on this machine any more but there ought to be a getch() function which simply gets a single character from standard in (stdin). If it doesn't exist and I can't recall which library it'd be in (my C++ book is gathering dust somewhere in this room) you can code up the functionality quite simply.

Option 1

Code: Select all

   cout << "You guessed right!"<<endl; 
   getch(); // pause the program to see the output.
   return 0; 
} 
Option 2

Code: Select all

   cout << "You guessed right!"<<endl; 
   char dummy;
   cin >> dummy;  //pause program to see the output
   return 0; 
} 
[edit]
If this is pure C, I believe the declaration in Option 2 will have to come before the assignment of Secret's value.
[/edit]

Posted: Fri Sep 19, 2003 9:53 am
by mo
Thanks Tallyrand,

I'm glad to hear I have TextPad set up properly and to learn that trick. Using the Windows Command Prompt in W2K is a lot of extra typing I don't need and also does not work the same way as a terminal window on Linux so I end up doing things twice (or more often)...energy I could spend actually learning something.

mo

EDIT: This is what I settled on (put in my clip library):

Code: Select all

int main()
{
   short Dummy;
   
   Dummy = 0;

   cout << "Waiting for you to shut down with \"0\", Dummy."<<endl;
   cin >> Dummy;
   return 0;
}