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

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.

#include <iostream>
#include <conio.h>
using namespace std;
#pragma warning(disable:  4996)

int main()
    int x = 0;
    x = getche();
    if(x == 0)
        // function and arrow keys here
        // They are made negative values here
        // so that they can be distinguished
        // from normal keys
        x = -getche();
    cout << x << "\n";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.