943,559 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 620
  • C++ RSS
May 10th, 2008
0

txt program?!HELP ME

Expand Post »
can u help me with this:
write a program that u can write in it and evrey time u press (F1) program will tell u number of capital letters in txt

if u press (F2) it tells u number of words(for exampel: 23 erf 3e has 3 words)

if u press any of the arrow keys cursor changes it`s position ,and when u
press back space it deletes the last character (just like the real back space)

thank u very much
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xlx16 is offline Offline
10 posts
since May 2008
May 10th, 2008
0

Re: txt program?!HELP ME

First
http://www.catb.org/~esr/faqs/smart-...html#writewell

Then perhaps
http://www.catb.org/~esr/faqs/smart-...html#beprecise

Then restate your question in English (not kiddie script), and state the Operating system and compiler you want this to run on. And try to be more specific than say "windows" and "borland" for example.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 10th, 2008
0

Re: txt program?!HELP ME

There is no standard way to do that in C or C++ because the languages don't know a thing about the function or arrow keys. But there are work-arounds and they all depend on your compiler and operating system.

One way is to use the curses library, or pdcurses on MS-Windows platforms. Its a little complicated and I'm not all that familiar with it.

Probably the easiest work-around is to use conio.h, if your compiler supports it. Below is a little program that illustrates one way to get function and arrow keys using getche(). When a special key is pressed you have to call getche() twice because the first time getche() returns 0 and the second time it returns the keycode for the key that was pressed. Special keys use the same key code as all other normal keys so you need to do something that will make them unique. I like to make them negative, but you could also just add 256 to them. Note this is the complexity of the MS-Windows operating system, not of the getche() function.

Run this program yourself and it will tell you the value of the key that was pressed, then you can use that value in your program for F1, F2, etc.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4. #pragma warning(disable: 4996)
  5.  
  6. int main()
  7. {
  8. int x = 0;
  9. x = getche();
  10. if(x == 0)
  11. {
  12. // function and arrow keys here
  13. // They are made negative values here
  14. // so that they can be distinguished
  15. // from normal keys
  16. x = -getche();
  17. }
  18. cout << x << "\n";
  19. }
Last edited by Ancient Dragon; May 10th, 2008 at 10:06 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ Class Design Resources
Next Thread in C++ Forum Timeline: i dont understand how this code thing works to put up a program. what does it mean?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC